每次打开任何实体的记录时,有没有办法自动触发自定义工作流程活动?
答案 0 :(得分:2)
当然,您可以使用在Form Load上运行的某些JavaScript的ExecuteWorkflow
请求。以下是从JavaScript调用ExecuteWorkflow
的示例。
http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html
答案 1 :(得分:2)
如果您想要触发自定义工作流程活动,并且不需要执行与其相关的任何工作流程,我建议您创建自定义操作。它与工作流程非常相似,但CRM将为您调用创建自定义端点。它消除了跟踪工作流ID的需要......
答案 2 :(得分:1)
您可以使用Plugin
代替自定义工作流程,并在“检索”消息上注册。
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);
}
}
}