Tuesday, 28 October 2014

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.
<<This Business Logic >>
             Else
            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.

Impact
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
<< Business Logic >>

2)     Schedule it on System’s Task Scheduler with the below Trigger. 
 

Impact
       We should have one Azure server to schedule the application.


Approach 1 VS Approach 2

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

--
Happy CRM’ing
Gopinath

No comments:

Post a Comment