Set default Business Process on a form while creating new record
Problem statement:
Unable to switch or set default Business Process on a form while creating new record.
Scenario:
Assuming a given entity (Case) has several forms associated with it and each form can be associated with one or more business processes. When a user tries to create a new record, the selected form will use the default Business Process for the entity – forcing them to update unnecessary fields that relate to this process flow and adding confusion.
Solution:
Via customization, users can add a simple script to automatically switch the BPF based on certain criteria on form load. In this sample, the criteria used is the form identity. In this way, each form can default to a specific BPF definition if required.
1. Create a Java Script Web Resource
//Java Script function setDefaultBPFForNewEntitieOnsFormLoad() { //GUID of the select form – can be found in the form URL var formGuid = 'A72C7955-442B-4EA4-9499-B10CD18B4256'; //GUID of the custom Business Process Flow – can be found in the Business Process URL var procesGuid = 'ABC62C8B-BE5E-4A74-B367-FC4A6222D2A4'; //If the entity is new and is not on the correct process id then re-direct. if ( (Xrm.Page.data.entity.getId() == null || Xrm.Page.data.entity.getId() == 'undefined'|| Xrm.Page.data.entity.getId() == '') && (Xrm.Page.context.getQueryStringParameters().process == null || Xrm.Page.context.getQueryStringParameters().process != procesGuid) ) { var parameters = {}; parameters["formid"] = formGuid; parameters["process"] = procesGuid; Xrm.Utility.openEntityForm("incident", null, parameters); // this opens the new case form with the specific process displayed. } }
It is recommended to add the new customization within a solution.
Copy and paste the Java Script above in the content editor – see screenshot below.
Make sure to save and publish all customizations.
2. Add the Java Script Web Resource to the selected form
Save and publish the form customizations.
To validate the change, open the select form to create a new record (new case), and the right Business Process Flow will be set on load.
Special thanks to Sam Piper!
– Smith Codio