Dynamics CRM 工作流因无限循环检测而失败 - 但为什么呢?

Dynamics CRM workflow failing with infinite loop detection - but why?

我想 运行 每 30 分钟一个插件,以轮询外部系统的变化。我在 CRM Online 中,所以我没有准备好访问计划引擎。

对于 运行 插件,我有一个 'trigger' 具有时区独立日期的实体-

更新字段也会触发一个工作流,在伪代码中有这样的逻辑:

If (Trigger_WaitUntil >= [Process-Execution Time])
{
  Timeout until Trigger:WaitUntil
  {
    Set Trigger_WaitUntil to [Process-Execution Time] + 30 minutes
    Stop Workflow with status of: Succeeded
  }
}
If Trigger_WaitUntil < [Process-Execution Time]) 
{
  Send email //Tell an admin that the recurring task has self-terminated
  Stop Workflow with status of: Canceled
}

因此,我期望的行为是每 30 分钟更新一次 'WaitUntil' 字段(并且再次触发插件和工作流);除非 WaitUntil 日期早于执行时间,在这种情况下停止工作流。

然而,大约 4 小时后(可能执行了 8 次,虽然我还没有验证)我收到了一个无限循环警告 "This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again. For information about workflow"。

我的问题是为什么?工作流是否有像插件一样的关联 ID,它被传递到子工作流?如果是这样,无论如何我可以阻止这种情况,同时保持当前使用单个触发记录来管理计划的基本机制(我已经看到其他解决方案,其中工作流创建新记录,但你必须绕过还要整理旧的触发记录)

是的,这种行为是众所周知的。在 Dynamics CRM 中实现没有无限循环问题且仅使用 OOB 功能的重复工作流的唯一方法是使用批量删除功能。本文介绍了如何实现它 - http://www.crmsoftwareblog.com/2012/08/using-the-bulk-deletion-process-to-schedule-recurring-workflows/

UPD:如果您想每 30 分钟 运行 您的代码,那么您将必须创建 48 个具有相应开始日期时间的批量删除作业,例如 12:00, 12: 30, 1:00 。 ..

CRM 当前支持的方法是使用 Azure Scheduler

摘录:

create a Web API application to communicate with CRM and our external provider running on a shared (free) Azure web site and also utilize the Azure Scheduler to manage the recurrence pattern.

The free version of the Azure Scheduler limits us to execution no more than once an hour and a maximum of 5 jobs. If you have a lot going on a month will get you executions every minute and up to 50 jobs - which sounds like a pretty good deal.

所以如果你想要每 30 分钟一次,你可以创建两个工作,一个在半小时,一个在整点。

批量删除是一个有趣的变通方法,我们以前用过。虽然它会产生额外的工作和维护,所以我尽可能避免它。

我通常建议构建一个 windows 应用程序并使用 windows 调度功能(我知道你说过你没有可用的调度程序,但这经常被遗忘)。这种方法非常有效,而且很容易排除故障。写入日志和发送错误电子邮件警报很容易使其健壮。服务器不需要外部访问,只需要到达CRM即可。如果您有本地 CRM,您可以只使用相同的服务器。

Azure Scheduler 是一个很好的建议。这让你保持在云中,这很好。

如果您已经安装了 KingswaySoft 或 Cozy Roc,SSIS 是另一种选择。

您可以构建一个工作流来创建另一条记录并自行清理;但是,这实际上是在使用错误的工具来完成这项工作。而且,它很容易失败,然后不启动下一条记录。

有一个解决方案叫做 "Scheduled Workflow Runner"。您创建一个 FetchXML 查询来创建 运行 的记录集,并将其指向您希望它在每条记录上 运行 的按需工作流。 http://alexanderdevelopment.net/post/2013/05/18/scheduling-recurring-dynamics-crm-workflows-with-fetchxml/