Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Branching and Programmatically Branching Process Flows

Post Author: Joe D365 |

Business Process Flows in Microsoft Dynamics CRM help guide users through their work while they are using CRM records. Organizations standardize processes across teams to provide consistency and visibility to process steps and stages. In this blog, we will at the new features of Business Process Flow (BPF) in CRM 2015, including branching and programmatically branching process flows.

The Scenario

Let's say you are working for a car insurance company. Customers or policy holders call your company to file claims or to inquire about existing claims, to update their account, etc. So, we need to build a standard business process to handle those phone calls and assist customers with their claims or inquiries. Here is the simple flow chart:

As a business user this can easily be set up using BPF. What will be needed: Entities to work with, Stages and Steps? The main Entities are going to be "Case" and "Claim" because Case is required for any call that is received and Claim is the custom Entity that stores Customer Claims data. In addition to these two Entities, we created another custom Entity called "Call Process" just to handle different type of calls. For a phone call regarding a Claim we will have the following Stages:

Pretty straight forward:

  • Identify the caller - if the Case already exists then update with an Activity otherwise create a new Case
  • If the Claim already exists – update/create a new Claim
  • End the call with comments

Branching Process Flows

In the insurance claim example, what happens when calls are merely for just an inquiry? The users do not need to access the claim; they only need to make sure to capture the details in the Case.

In CRM 2015, you can handle this situation by adding one or more branches in our design. In the example below, you have one field in our "Identify" stage called "Type of Call" and its values are simply "About Claim" and "About Inquiry." Depending on which one is selected by the user you would want to follow different processes. So, you can easily create one branch that will check for the selection and route to an appropriate stage in the business process flow.

Keep in mind even though you have this flexibility, you want to limit the number of branches within a single business process because it can get tough to maintain. It will clutter your design.

Programmatically Branching Process Flows

You could achieve the same behavior by writing client scripts on the form. Now, in 2015 you have additional methods added to the "Xrm.Page.data" and "Xrm.Page.ui" namespaces. Please refer to SDK for available methods. The script would look something like this:

This is just an example of what you can do using client scripts. This code will switch to the right process based on "Type of Call" value selected.

Scripts can be even more powerful when you need to pull data from another system. For example, you may need to verify some information entered, and based on that, route users to the correct stage or entirely whole new process.

Let's try to understand the methods used in the script. The object model looks something like this:

After all the required steps are completed in our "Identify" stage, users will click on "Next Stage" button to move forward. At this point you want to check for "Type of Call" and re-route the user to a different process if selected value is "About Inquiry". A few points:

  1. You need to tie up our method to "Next Stage" button. For that you can use "addOnStageChange()" method of the Xrm.Page.data.process namespace. This event can be fired anytime active stage of a business flow changes. To register this event you have to use OnLoad event of the form. When it's fired you can capture information on the Active stage by calling "eventArgs.getStage()".

     

  2. By using the "Stage" object you can know about its ID, Name and if it is Active/InActive. In addition, this object can get us list of Steps within a Stage "stage.getSteps()". You can iterate through each step in the collection and find the one you are looking for by checking attribute name by using method "step.getAttribute()". Once you have found out the right attribute you can easily get the selected value.
  3. Next thing you need to do is to switch to the correct process. For that, you need get to list of enabled processes within the current entity using method "Xrm.Page.data.process.getEnabledProcesses()". This will return list of enabled processes. Using the process object you can determine process ID, Name, its Stages, etc. Now, you can easily set the active process to "Phone to Inquiry Process" by calling "Xrm.Page.data.process.setActiveProcess()" method.

That's all! This is a great new feature since it provides the user with more control over Business Process Flow. You can now more easily find out where the user is at in the process flow in real time. This opens up many possibilities.

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends