Scheduled Workflow in CRM 2013/2011

Scheduled Workflow in MSCRM 2013/2011

There was a requirement for us to write an application which should run on every month 1st 12:00 AM.
Approach 1

1.     Create two Date Time fields as ‘WorkflowRunDate’ and ‘FirstWorkingDateOfNextMonth’, which are hidden on the User Entity.
2.     Create a System Workflow (On Demand and Child Workflow).
3.     Create a Custom Workflow
Custom workflow Pseudo Code
If (WorkflowRunDate is null or FirstWorkingDateOfNextMonth Equals to WorkflowRunDate)
Update WorkflowRunDate with Current Date +1
Update FirstWorkingDateOfNextMonth on User Record.
            WorkflowRunDate = WorkflowRunDate + 1 Day ( 12:00 AM)
4.     The Wait condition in the workflow will be set to trigger at the time “WorkflowRunDate” for the next consecutive date.

Note: We did find an issue of workflow triggering twice, so added wait for 5 mins steps. As the time is controlled by our custom workflow we didn’t get any issue in adding that step.

1)     The workflow should be triggered manually by the user who has access on respective accounts of the user record.
2)     We should have two fields on the User Record.
3)     We should never de-activate/disable the user record.
4)     Workflow runs for 24/7.
5)     If there are any changes to the business logic, we should check the dates carefully and trigger it again.
Approach 2
1)     Create a Console Application in C# code.
Console Application Pseudo Code
2)     Schedule it on System’s Task Scheduler with the below Trigger. 
       We should have one Azure server to schedule the application.
Approach 1 VS Approach 2

Approach 1
Approach 2
Triggering is manual
No manual trigger, initial configuration on server is needed
Whenever there is a change in the logic, the workflow should be triggered again.
Its automatic
Date Logic is Programmatical
Task scheduler takes care of it
Dependency on User Record
No dependency on any record
Workflows runs for 24/7
Task scheduler takes care of it
No server needed
Need a server for scheduling the job
Included in Dynamics CRM
Not included in Dynamics CRM
No server maintenance cost
Server maintenance should be taken care

Happy CRM’ing


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s