2

I want to run a plug-in every 30 minutes, to poll an external system for changes. I am in CRM Online, so I don't have ready access to a scheduling engine.

To run the plug-in, I have a 'trigger' entity with a timezone independent date-

Updating the field also triggers a workflow, which in pseudocode has this logic:

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
}

So, the behaviour I expect is that every 30 minutes, the 'WaitUntil' field gets updated (and the Plug-in and workflow get triggered again); unless the WaitUntil date is before the Execution time, in which case stop the workflow.

However, 4 hours or so later (probably 8 executions, although I haven't verified that yet) I get an infinite loop warning "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".

My question is why? Do workflows have a correlation id like plug-ins, which is being carried through to the child workflow? If so, is there anyway I can prevent this, whilst maintaining the current basic mechanism of using a single trigger record to manage the schedule (I've seen other solutions in which workflows create new records, but then you've got to go round tidying up the old trigger records as well)

4 Answers 4

2

Yes, this behavior is well-known. The only way to implement recurring workflows without issues with infinite loops in Dynamics CRM and using only OOB features is usage of Bulk Deletion functionality. This article describes how to implement it - http://www.crmsoftwareblog.com/2012/08/using-the-bulk-deletion-process-to-schedule-recurring-workflows/

UPD: If you want to run your code every 30 mins then you will have to create 48 bulkdelete jobs with correspond startdatetime like 12:00, 12: 30, 1:00 ...

1
  • I'd definitely consider using the Bulk Deletion technique for daily jobs; but my original request is predicated on a 30 minute cycle, and I do not know of a sensible way to get Bulk Deletion to do that
    – cseymr
    Commented Nov 24, 2015 at 13:50
1

The current supported method for CRM is to use the Azure Scheduler.

Excerpt:

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 $20 a month will get you executions every minute and up to 50 jobs - which sounds like a pretty good deal.

so if you wanted every 30 minutes, you could create two jobs, one on the half hour, and one on the hour.

1
  • I had in the back of my mind wondered about using Azure, so it's very helpful to have the pointer to Jason's example. Thank you
    – cseymr
    Commented Nov 25, 2015 at 10:07
1

The Bulk Deletion is an interesting work around and something we've used before. It creates extra work and maintenance though so I try to avoid it if possible.

I would generally recommend building a windows application and using the windows scheduling feature (I know you said you don't have a scheduler available but this is often forgotten). This approach works really well and is very easy to troubleshoot. Writing to logs and sending error email alerts is pretty easy to make it robust. The server doesn't need to be accessible externally, it only needs to reach CRM. If you had CRM on-prem, you could just use the same server.

Azure Scheduler is a great suggestion. This keeps you in the cloud which is nice.

SSIS is another option if you already have KingswaySoft or Cozy Roc in place.

You could build a workflow that creates another record and cleans up after itself; however, this is really using the wrong tool for the job. Also, it's very easy for it to fail and then not initiate the next record.

0

There is a solution called "Scheduled Workflow Runner". You create a FetchXML query to create a record set to run against, and point it at an on-demand workflow that you want it to run on each record. http://alexanderdevelopment.net/post/2013/05/18/scheduling-recurring-dynamics-crm-workflows-with-fetchxml/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.