Switch BPF in Dynamics 365 using JavaScript

In today’s blog, we will cover how to change the BPF using JavaScript in the unified interface when the form loads based on a custom field Lead Type on the Lead form. Let’s take a closer look!

Steps –

  1. In the example below, we have a new option set field called Lead Type with values of TAB Member and TBO. When the Lead Type has a value of TAB Member, update the business process flow to the TAB Member BPF and when the value is TBO, update the business process flow to TBO BPF.

2. Create two separate BPFs for the required entity. In this case, we created two separate BPFs for the Lead entity.

3.  From each BPF, grab the record GUID using the console.

var currentBpfID = Xrm.Page.data.process.getActiveProcess().getId();

4. JavaScript Code-

 var SwitchBPF ={
    checkSwitchBPFbyType: function(executionContext)
    {


        //For example
        // TAB Member 100000000 | Process Flow TAB Member : 65dd48aa-cf41-4f12-8523-7296097c8893
        // TBO        100000001 | Process Flow TBO: 890f4df6-eb4f-413d-8936-f62aaa9b2798
        var formContext = executionContext.getFormContext();
        if(formContext.data.entity.getEntityName() == "lead")
        {
            if(formContext.data.process.getActiveProcess() != null)
            {
                //Check Type & BPF match as required
                var currentBpfID = formContext.data.process.getActiveProcess().getId();
                if(formContext.getAttribute("cf_leadtype"))
                {
                    var leadType = formContext.getAttribute("cf_leadtype").getValue();
                    if(leadType == "100000000" && currentBpfID != "65dd48aa-cf41-4f12-8523-7296097c8893")
                       formContext.data.process.setActiveProcess("65dd48aa-cf41-4f12-8523-7296097c8893");
                    else  if(leadType == "100000001" && currentBpfID != "890f4df6-eb4f-413d-8936-f62aaa9b2798")
                       formContext.data.process.setActiveProcess("890f4df6-eb4f-413d-8936-f62aaa9b2798");
                }
            }
        }
    

Results –

Hope this helps!!


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange