摘要: 本人微信公众号:微软动态CRM专家罗勇 ,回复289或者20181221可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me 。
我们都知道,默认情况下Dynamics 365执行的插件有2分钟的限制,若达到2分钟还没有执行完毕,会触发异常,类似如下:
System.TimeoutException: Couldn’t complete execution of the custom activity *** plug-in within the 2-minute time limit.
那我改到工作流行不行?如果改到自定义工作流活动,同样也有类似的限制,一个自定义工作流活动的执行时间不能超过2分钟,若超过了,会触发异常,和插件的异常是一样的。
如果碰到这种情况怎么办?
若是工作流中有多个循环的话,考虑将这个循环拆出来,每个循环的逻辑用一个异步工作流来做,这个异步工作流设置为仅仅支持手工触发,记得,一定要设置成支持手工触发。
然后这个循环体里面的就用调用工作流来代替,类似如下的代码,这样在很多情况下就可以绕过这个2分钟的限制。
var fetchXml = @"<fetch version='1.0' mapping='logical' distinct='false' no-lock='true'>
<entity name='workflow'>
<attribute name='workflowid' />
<filter type='and'>
<condition attribute='type' operator='eq' value='1' />
<condition attribute='category' operator='eq' value='0' />
<condition attribute='name' operator='eq' value='{your workflow name}' />
<condition attribute='statecode' operator='eq' value='1' />
</filter>
</entity>
</fetch>";
var workflowEntities = orgSvc.RetrieveMultiple(new FetchExpression(fetchXml));
if (workflowEntities.Entities.Count == 0)
{
tracingService.Trace("Workflow does not exist or activated.");
return;
}
foreach (var item in scEntities.Entities)
{
ExecuteWorkflowRequest req = new ExecuteWorkflowRequest()
{
EntityId = item.Id,
WorkflowId = workflowEntities.Entities[0].Id
};
orgSvc.Execute(req);
}