HOW TO CHANGE BUSINESS PROCESS FLOW ON CHANGE OF FORM IN AN ENTITY IN DYNAMICS 365?

There may be cases where you need to set different Business Process Flow for different forms in an entity in Dynamics 365.
Maximum number of processes, stages, and steps
To ensure acceptable performance and the usability of the user interface, there are some limitations you need to be aware of when you plan to use business process flows:

  • There can be no more than 10 activated business process flow processes per entity.
  • Each process can contain no more than 30 stages.
  • Multi-entity processes can contain no more than five entities.

SCENARIO:

On the Donor Cycle entity (Custom Entity), we have two forms named “Managed Donor Cycle” and “Annual Fund Donor Cycle”. If we change one form to another form, automatically Business Process Flow will also change. Following is the process explained to achieve this requirement.

Navigation Steps:
Step 1: Create two forms on an entity as shown in the following screenshots:

  • Managed Donor Cycle
  • Annual Fund Donor Cycle
Business-Process-Flow1






Step 2: Create two Business Process Flows on an entity.

Step 3: Create a Web Resource where the type is “Jscript”.

JavaScript Code:
function formBasedBPF(executionContext)
{

debugger;
var formType = Xrm.Page.ui.getFormType();
// Getting Form Type
formContext = executionContext.getFormContext();
// Getting Form Context
var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
// Getting Form Name
var activeProcess = Xrm.Page.data.process.getActiveProcess();
// Getting Name
if (activeProcess.getId() != null)

{
var activeProcessID = activeProcess.getId();
if (formType != 1 && formName == “Managed Donor Cycle” &&
                        activeProcessID.toUpperCase() != “DEEC5EF0-9F6D-4D6D-8878-65E7473A9921”)
    // “DEEC5EF0-9F6D-4D6D-8878-65E7473A9921” – GUID of the Managed Donor
// Cycle Business Process Flow

{
formContext.data.process.setActiveProcess(“DEEC5EF0-9F6D-4D6D-8878- 65E7473A9921”,
“success”);  
     }

else if (formName == “Annual Fund Donor Cycle” && activeProcessID.toUpperCase() !=
“7CBE0333-7D3F-49F1-AAAF- 0B2C746C67FB”)
 
// “7CBE0333-7D3F-49F1-AAAF-0B2C746C67FB” – GUID of Annual Fund Managed Donor Cycle
//Business Process Flow

{
formContext.data.process.setActiveProcess(“7CBE0333-7D3F-49F1-AAAF- 0B2C746C67FB”,
“success”);
          }
}
}

Step 4: Trigger the above function on the “Onload” of both forms.

Output:

Leave a Reply