Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

setActiveProcess JavaScript function not switching enabled business process flows on case entity

(0) ShareShare
ReportReport
Posted on by 190

We are using setActiveProcess to set the business process flow on the case form based on case record owner. We have several business process flows on the case entity. We have published them on the new Customer Service Hub app and we can switch between the processes via the ribbon button.

The JavaScript function works fine in the old legacy UI but not in the new Unified Interface. The callback function returns 'Invalid'

getActiveProcess and getEnabledProcesses work in the new UI.

Here if the function we are using:

function SetBPF() {
 
    if (Xrm.Page.ui.getFormType() === 1) {
        var activeProcess = Xrm.Page.data.process.getActiveProcess();
        if (activeProcess != undefined && activeProcess != null) {
            var activeProcessId = Xrm.Page.data.process.getActiveProcess().getId();

            var ownerName = Xrm.Page.getAttribute("ownerid").getValue()[0].name;

            if (ownerName != null && ownerName != undefined && activeProcessId != null) {

                if (ownerName.toUpperCase() == TeamName&& activeProcessId.toUpperCase() != ProcessName) {
                    Xrm.Page.data.process.setActiveProcess(ProcessGUID, successCallback);
                }
                else if (ownerName == TeamName&& activeProcessId.toUpperCase() != ProcessName) {
                    Xrm.Page.data.process.setActiveProcess(ProcessGUID, successCallback);
                }
                else if (ownerName.toUpperCase() != TeamName&& ownerName != TeamName && activeProcessId.toUpperCase() != ProcessName) {
                    Xrm.Page.data.process.setActiveProcess(ProcessGUID, successCallback);
                }
            }
        }
    }
}

Any ideas why this function might not work in the new UI?

Thanks

Phil

  • fillcrocker Profile Picture
    fillcrocker 190 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    This seems like a lifetime ago but as I recall the solution MS offered did not work. As you can see from the post history MS said that setActiveProcess no longer works in the new UI though I find it does but only after the record is saved.  It only happened for new records so I had to resort to calling the function after the first save. Luckily the customer was happy for the BPF not to be availably until then.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hi Henry,

    Until 2 days ago could use Xrm.Page.data.process.setActiveProcess(null); it still working on UAT, TEST but on DEV I getting an error which needs ProcessId. Do you have experience to solve this issue?

  • DG_developer Profile Picture
    DG_developer 5 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hello Phil,

    Did you received any workaround or solution for this issue from Microsoft?

    Thanks :)

  • Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Thanks Phil.

    This looks like a known issue. Let me know if the proposed workaround works for you.

    I’ll try to follow up on this as well.

    Henry

  • fillcrocker Profile Picture
    fillcrocker 190 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hi Henry,

    Ticket number is: 119122824000367

    Thanks

    Phil

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hi Phil,

    Do you have the case number?
    There might be a misunderstanding between the SetProcess message that used to be available in workflow custom actions (and that is indeed deprecated) and the setActiveProcess client API that is supported and documented.

    Indeed, as a workaround you could test the form type with the getFormType method, and if it's 1 (Create), hide the Business Process Flow using the setVisible method, and once the record is saved, switch to the appropriate Business Process Flow and display it. But that means users would have to start working on records without guidance.

    Henry

  • fillcrocker Profile Picture
    fillcrocker 190 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Microsoft replied to my ticket to say the setActiveProcess can not be used in the new UI and referred me to this article: docs.microsoft.com/.../model-business-process-flows

    I am confused at this response because it does seem to work for saved case records. So I assume then that the issue is how the form and components are loaded now in the new UI. They have given me some sample code to try. I will need to change for the case entity:

    function doSomething(executionContext) {

    var formContext = executionContext.getFormContext(); // get the form Context

    var recid = formContext.data.entity.getId();

    recid = recid.replace("{", "").replace("}", "");

    var entityFormOptions = {};

    entityFormOptions["entityName"] = "opportunity";

    entityFormOptions["entityId"] = recid;

    entityFormOptions["useQuickCreateForm"] = false;

    // Set default values for the Contact form

    var formParameters = {};

    // Open the form.

    Xrm.Navigation.openForm(entityFormOptions, formParameters).then( function (success)

    { console.log(success); }, function (error) { console.log(error); });

    var req = new XMLHttpRequest();

    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/SetProcess", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    //req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function ()

       {

           if (this.readyState === 4) {

               req.onreadystatechange = null;

               if (this.status === 204) {

                   //result = JSON.parse(this.response);  

                   //callback(result);

      Xrm.Navigation.openForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

      //formContext.data.refresh(true);

               } else {

                   Xrm.Navigation.openAlertDialog(this.statusText);

               }

           }

       };    

    req.send(JSON.stringify(

          {

     "Target": {"@odata.type": "Microsoft.Dynamics.CRM.opportunity", "opportunityid": recid},

     "NewProcess":{"@odata.type": "Microsoft.Dynamics.CRM.workflow", "workflowid": "e95233b8-42b4-4432-a941-ed387a4206c2"} // Desiered BPF to change to

    }

          ));

    }

    Not sure this is going to do what I want. I might just hide the BPF and switch onLoad of the record after the first save.

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hi Phil,

    I can reproduce the issue in the console, even after the form has completely finished loading.

    I'm not sure if this is the expected behavior, so I suggest that you open a Support Request for this, focusing on the setActiveProcess method not working in create mode in the Unified Interface.

    admin.powerplatform.microsoft.com/support

    Let me know how that goes.

    Henry

  • fillcrocker Profile Picture
    fillcrocker 190 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    I have discovered that this behaviour is only happening for new records. We are triggering the function on the load of the form and before the record has been saved. This worked fine in the old UI but seems to be a problem in the new Unified Interface. The function seems to be firing before the business process has loaded on the form. In the old UI the the default BPF is visiable before the JavaScript triggers. Is this a case of the BPF's loading in a different order now in the new UI? If so how do I control the timimng of the JavaScript on load?

  • fillcrocker Profile Picture
    fillcrocker 190 on at
    RE: setActiveProcess JavaScript function not switching enabled business process flows on case entity

    Hi Henry,

    Sorry that was a bad example of code.  I altered it slightly for this question because I thought it would make more sense. Here is the actual code:

    function SetBPF() {

    debugger;

       if (Xrm.Page.ui.getFormType() === 1) {

           var activeProcess = Xrm.Page.data.process.getActiveProcess();

           if (activeProcess != undefined && activeProcess != null) {

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

               var ownerName = Xrm.Page.getAttribute("ownerid").getValue()[0].name;

               if (ownerName != null && ownerName != undefined && activeProcessId != null) {

                   if (ownerName.toUpperCase() == TeamName.ECT && activeProcessId.toUpperCase() != ProcessName.ECT) {

                       Xrm.Page.data.process.setActiveProcess(ProcessName.ECT, successCallback);

                   }

    else if (ownerName == TeamName.AOB && activeProcessId.toUpperCase() != ProcessName.AOB) {

                       Xrm.Page.data.process.setActiveProcess(ProcessName.AOB, successCallback);

                   }

                   else if (ownerName.toUpperCase() != TeamName.ECT && ownerName != TeamName.AOB && activeProcessId.toUpperCase() != ProcessName.ContactCenter) {

                       Xrm.Page.data.process.setActiveProcess(ProcessName.ContactCenter, successCallback);

                   }

               }

           }

       }

    }

    We have hard coded the BPF GUID's earlier in the form script so ECT, AOB and Contact Center all reference different BPF's.

    getActiveProcess brings back the BPF that is first in the list where I have specified the process order for the case entity

    getEnabledProcesses brings back all the BPF's I have enabled for the new App ( I have tried retrieving the enabled BPF GUID's and then setting the active GUID to one of these enabled BPF's. I then call getActiveProcess but it still returns the BPF specified at the top of the process order list. If I change the order of this list then getActiveProcess will return that BPF.

    I am able to swiitch between the 3 BPF's in the JavaScript manually using the 'Switch Process' ribbon button so that leads me to beleive they are enabled.

    I did also try using formContext.data.process.setActiveProcess (and will change to this eventually) but I still get the same result.

    I will try as you suggested testing in the browser console.

    Thanks again.

    Phil

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,883 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,569 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans