As part of the extension to Dynamics CRM, we may need to manipulate Business Process Flow programmatically.
If you see, Page Object Model, Process can be accessed from these two
- Xrm.Page.data.process – provides events, methods, and objects to interact with the business process flow data in a form
- Xrm.Page.ui.process – provides methods to interact with the business process flow control in a form.
Steps to achieve this – This is very simple. You just need to do two steps and you achieve the goal.
Step # 1 – Write the following code. Code is explained below –
- Method to be attached to Form OnLoad
- Getting the name of the current stage of Business Process Flow.
- Printing the Stage name in Console.
- Since one stage can have multiple steps, so fetching a collection of steps from current active stage,
- Printing the step name and its business requirement.
- Attaching an event handler for Stage Change event.
- Implementation of Event Handler in #6.
Save and Publish the Web Resource. Top manage Web resources from Visual Studio please see my this article – Manage Dynamics CRM Web Resources from Visual Studio
Step # 2 –
Add Web Resource and attach the function to Form OnLoad as shown below.
Be informed that we can have up to 50 Event Handlers for an Event. Also note here, I have used two event handler but disabled the another one. Omit parentheses from function Name as shown below.
Save and Publish the changes.
Open the Entity form and Developer tool (F12) of the browser. You will see the first out as below
Now I will try to move to the Nest Stage and I get this output –
Please note here – Stage Change event will be fired either I move to next stage or previous stage.
Hope this helps you to start with.
Happy Dynamics’ing !!!