打开记录时自动触发工作流
Automatically trigger a workflow when a record is opened
有什么方法可以在每次打开任何实体的记录时自动触发自定义工作流程Activity?
当然,您可以使用来自某些 JavaScript 在表单加载时运行的 ExecuteWorkflow
请求。这是从 JavaScript.
调用 ExecuteWorkflow
的示例
http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html
您可以使用 Plugin
而不是自定义工作流程,并将其注册到 "Retrieve" 消息中。
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
if (context.Depth == 1)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Obtain the target entity from the input parmameters.
EntityReference entity = (EntityReference)context.InputParameters["Target"];
ColumnSet cols = new ColumnSet(
new String[] { "lastname", "firstname", "address1_name" });
var contact = service.Retrieve("contact", entity.Id, cols);
if (contact != null)
{
if (contact.Attributes.Contains("address1_name") == false)
{
Random rndgen = new Random();
contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());
}
else
{
contact["address1_name"] = "i already exist";
}
service.Update(contact);
}
}
}
如果您想要触发自定义工作流 activity,并且不需要在其中执行任何与工作流相关的操作,我建议您创建一个自定义操作。它与工作流非常相似,但 CRM 会创建一个自定义端点供您调用。它消除了跟踪工作流 ID 的需要...
有什么方法可以在每次打开任何实体的记录时自动触发自定义工作流程Activity?
当然,您可以使用来自某些 JavaScript 在表单加载时运行的 ExecuteWorkflow
请求。这是从 JavaScript.
ExecuteWorkflow
的示例
http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html
您可以使用 Plugin
而不是自定义工作流程,并将其注册到 "Retrieve" 消息中。
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
if (context.Depth == 1)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Obtain the target entity from the input parmameters.
EntityReference entity = (EntityReference)context.InputParameters["Target"];
ColumnSet cols = new ColumnSet(
new String[] { "lastname", "firstname", "address1_name" });
var contact = service.Retrieve("contact", entity.Id, cols);
if (contact != null)
{
if (contact.Attributes.Contains("address1_name") == false)
{
Random rndgen = new Random();
contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString());
}
else
{
contact["address1_name"] = "i already exist";
}
service.Update(contact);
}
}
}
如果您想要触发自定义工作流 activity,并且不需要在其中执行任何与工作流相关的操作,我建议您创建一个自定义操作。它与工作流非常相似,但 CRM 会创建一个自定义端点供您调用。它消除了跟踪工作流 ID 的需要...