【问题标题】:Automatically trigger a workflow when a record is opened打开记录时自动触发工作流
【发布时间】:2016-03-19 14:46:59
【问题描述】:

是否有任何方法可以在每次打开任何实体的记录时自动触发自定义工作流活动?

【问题讨论】:

    标签: dynamics-crm-2011 dynamics-crm-2013 dynamics-crm-online dynamics-crm-2015


    【解决方案1】:

    当然,您可以使用来自在表单加载上运行的某些 JavaScript 的 ExecuteWorkflow 请求。这是从 JavaScript 调用 ExecuteWorkflow 的示例。

    http://www.mscrmconsultant.com/2013/03/execute-workflow-using-javascript-in.html

    【讨论】:

      【解决方案2】:

      如果您想触发自定义工作流活动,并且不需要在其中执行任何与工作流相关的操作,我建议您创建自定义操作。它与工作流非常相似,但 CRM 会创建一个自定义端点供您调用。它消除了跟踪工作流 ID 的需要...

      【讨论】:

        【解决方案3】:

        您可以使用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);
            }
          }
        }
        

        CRM 2011–Retrieve Plugin

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-11-17
          • 2017-10-31
          • 1970-01-01
          • 2015-04-04
          • 1970-01-01
          • 1970-01-01
          • 2021-03-18
          • 1970-01-01
          相关资源
          最近更新 更多