Use JavaScript to automatically select the correct Business Process Flow based on a Field Attribute in Dynamics CRM 2015

Use JavaScript to automatically select the correct Business Process Flow based on a Field Attribute in Dynamics CRM 2015

 

With the release of Dynamics CRM 2015, it is now possible to use JavaScript to change the selected Business Process Flow based on a Field Attribute’s value. The Xrm.Page.data namespace is extended to include methods under Xrm.Page.data.process. . The full JavaScript code is given below:

Please call the function switchCaseProcess() to change the Business Process Flow.

// JavaScript source code

function switchCaseProcess() {

    var selectedProcessName = Xrm.Page.data.entity.attributes.get(“casetypecode”).getText();

    if (selectedProcessName != null)

    {

        selectProcess(selectedProcessName);

        Xrm.Page.data.entity.save()

    }

}

 

 function selectProcess(processName)

{

    switch (processName)

    {

        case “NBN Order”:

            //alert(processName);

            var processId = “5b101303-3e69-4eff-b245-b0ea3515cedb”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        case “Hosted Voice”:

            //alert(processName);

            var processId = “75378293-2ab7-4e47-9ae5-49ec31cc6fa2”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        case “PSTN Connection”:

            //alert(processName);

            var processId = “14c81567-3d7e-4c48-882d-b8886c7caf11”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        case “Fault”:

           // alert(processName);

            var processId = “3be91aac-f9ef-48c2-ad50-21dc66134f45”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        case “Carrier Credit Claim”:

            //alert(processName);

            var processId = “8d097a8b-213c-45ef-9ae3-ff57714e2ae3”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        case “Ethernet Order”:

           // alert(processName);

            var processId = “1cda4044-68ed-44cc-b885-e01ccb58536b”;

            Xrm.Page.data.process.setActiveProcess(processId, switchProcessEnd);

            break;

        default:

           // alert(“defaullt ” + processName)          

    }

}

 

 function switchProcessEnd(result) {

     if (result == “success”) {

        // alert(“Yes”);

     }

     if (result == “invalid”) {

        // alert(“Not done”);

     }

 }

 

3,283 total views, 1 views today

About Author

Ricky Saini

Ricky Saini
Dynamics CRM, SharePoint, Office 365, Windows Azure and .Net Architect/Consultant/Freelancer in Australia ( Melbourne, Sydney and Canberra)

Leave a Comment