Business Process Flow with JavaScript

Posted by

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

  1. Xrm.Page.data.process – provides events, methods, and objects to interact with the business process flow data in a form
  2. Xrm.Page.ui.process – provides methods to interact with the business process flow control in a form.

BPF_6

 

Scenario – For my entity, I have following stages and each stage has some steps. I will be accessing this information using JavaScript and be capturing Stage change event.

BPF_3

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 –

BPF_2_Code

  1. Method to be attached to Form OnLoad
  2. Getting the name of the current stage of Business Process Flow.
  3. Printing the Stage name in Console.
  4. Since one stage can have multiple steps, so fetching a collection of steps from current active stage,
  5. Printing the step name and its business requirement.
  6. Attaching an event handler for Stage Change event.
  7. 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.

BPF_5

Save and Publish the changes.

Output 

Open the Entity form and Developer tool (F12) of the browser. You will see the first out as below

BPF_1

 

Now I will try to move to the Nest Stage and I get this output –

BPF_4

 

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 !!!

References –

  1. https://msdn.microsoft.com/en-us/library/gg328474.aspx
  2. https://msdn.microsoft.com/en-us/library/dn817860.aspx
  3. https://msdn.microsoft.com/en-us/library/dn817878.aspx

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s