Posts Tagged ‘switch’

Switch Business Process Flow using Jscript based on CRM form’s field value

April 30, 2016 1 comment

Recently we got a requirement to switch the Business process on Case form based on ‘Case Origin’.

Its easily achievable using Jscript “setActiveProcess” method., callbackFunction);

  • processId‘ is the GUID of the ‘Business Process Flow’. You can copy the GUID from URL.
  • Go to ‘Settings –> Processes’ open the ‘Business Process Flow’ and copy the value from ‘id’ parameter, between %7b %7d
Copy Business Process ID

Copy Business Process ID

  • ‘callbackFunction’ is your custom JScript function name which gets triggered post ‘Business Process’ switch.

Below are the scenario and steps.

  • I have 3 Active Business Process Flows on my ‘Case’ entity.
Active Business Process Flows

Active Business Process Flows

  • ‘Business Process Flows’ are Security Role Based, so if my user has access to all 3 ‘Business Process Flows’, he can switch the process using ‘Switch Process’option.
Swicth Business Process

Swicth Business Process

Multiple Business Process Flows

Multiple Business Process Flows

  • In my scenario, ’Switch Process’ should happen based on ‘Case Origin’ field.
    • If ‘Case Origin’= Phone; Set “Business Process1”
    • If ‘Case Origin’= Email; Set “Business Process2”
  • Below is the script

function onload() {
// If not new Case form
if (Xrm.Page.ui.getFormType() != 1) {
// Read Origin Option text
var origin =“caseorigincode”);

if (origin && origin.getText()) {
var caseOrigin = origin.getText();

// Get Business process flow id
var processFlow1Id = “6CD44946-0DC5-47E3-9B62-6D7309254710”;
var processFlow2Id = “0B3A94CD-CD43-4F49-A9A3-93C4AC684CFA”;

// Get Current Active Process Id
var activeProcess =;
var currProcessId = activeProcess.getId();

if (caseOrigin.toLowerCase() == “phone”) {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow1Id.toLowerCase()) {
// Switch to the “Process Flow 1”, myCallBack);
} else if (caseOrigin.toLowerCase() == “email”) {
// Change the process only if current Active Process not the Target one
if (currProcessId.toLowerCase() != processFlow2Id.toLowerCase()) {
// Switch to the “Process Flow 2”, myCallBack);

// Call back function post Process flow switch
function myCallBack(response) {
if (response == “success”) {
alert(“BPF changed !!!”);
// Save the form;
else {
alert(“Error changing BPF!!!”);

How do I use the script?

  • Copy the script and create a new ‘Web resource’ in CRM and add to ‘Case’ form.
  • Register ‘onload()’ function on form onload event.
Register onload event - Case form

Register onload event – Case form

  • Publish the Customizations.
  • Open the Case record and based on ‘Case origin’ system auto switches to the Business process Flow.
New Business Process Selected

New Business Process Selected

Key points on multiple ‘Business process flows’:

  • You can have up to 10 active business process flows per entity.
  • You can associate business process flows with security roles so that only people with those security roles can see or use them.
  • In case of multiple Active ‘Business process flows’, the first activated business process flow in that list is the one that will be applied by default.
  • Each record can have only one business process flow at a time.
  • If someone’s security roles do not allow them to use a specific business process flow, the current business process flow will be visible, but disabled.