1

我面临一个奇怪的问题,我在网上找不到合适的解决方案。虽然在此链接下的 Microsoft Dynamics CRM 论坛上提出了类似的问题,但没有提到如何处理这种情况。

我在 CRM 2011 中设计了一个工作流,它应该在应用程序的单个字段更改(应用程序阶段)上触发,因为我在Start when: "Record fields change"下检查了Application Stage字段。

现在的问题是工作流触发了两次,也许是通过 JavaScript 代码触发的一次:

Xrm.Page.data.entity.save();  

另一个通过更新插件在同一实体上执行以响应上面的 JavaScript 代码。

我设计的工作流程/流程是一种主工作流程,它具有基于各自应用阶段启动的其他子流程。现在在子进程中,我创建了一个与应用程序阶段相关的活动并做其他事情,但由于工作流启动两次,它正在创建活动并多次执行其他任务。

应对这种情况的可行解决方案是什么?

4

2 回答 2

1

That JavaScript will definitely trigger the workflow once - it is no different from the user just clicking save.

A plugin which performs an update (e.g. service.Update(...)) will also trigger the workflow, that's all intended behavior.

I would start by looking at your plugin, mainly does it have to perform an update call? If you can avoid the double update that should solve your problem.

Did you know that a plugin can make data changes with an update call? If your plugin is registered synchronously and on the pre-event, then any change you make to the target entity object is reflected on the record, this doesn't trigger an additional update - its part of the original message.

For example, if the following code was registered on a pre-event, synchronous plugin the 'new_field' would be populated with "My new value" and no additional update calls are required.

//get the entity 
Entity entity = (Entity)context.InputParameters["Target"];

//set new field
entity["new_field"] = "My new value";

//end of plugin

Failing that it might be worth looking into other options:

  1. If the plugin is setting the application stage, why is the JavaScript also setting it?
  2. Is a plugin even required, could it all just go in a workflow?
  3. May you could look at using a do not run workflow field, the field is set by the plugin/JavaScript then when the workflow runs if that field is set it does nothing, but clear the field (not really a recommended option).
  4. Could the plugin trigger the workflows? Perhaps this could be read from a configuration record?
于 2013-07-07T17:46:36.843 回答
0

关于插件,当它触发更新时,上下文将只包含已更改的字段。

关于 Javascript.. 我认为所有字段都被发送到上下文,所以就像所有字段都有一个更新,所以工作流程会触发。

最简单的解决方案是在记录上设置一个标志,这样它只会触发一次。例如,该字段可以是一个名为“flag”的布尔值。在工作流程开始时,您可以检查该值并让它继续依赖它。

例如:

  • 如果(标志 == 假)

    • 做我的逻辑…………
  • 设置标志=真

你怎么看?

干杯,

马里奥

于 2013-07-08T09:40:22.280 回答