web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Change Business process flow as per form selected

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

I am having 3 different forms for custom entity and 2 business process flows(Dynamics CRM 365 Online). I want to display business process flow as per the form selected. In below script, I am getting "invalid" result in callbackFunction and BPF is not setting on the form. Both BPFs are activated on the screen.

function ChangeProcess(executionContext) {
//debugger;
var formContext = executionContext.getFormContext();
var formLabel = formContext.ui.formSelector.getCurrentItem().getLabel();
var guid1 = "bE0E84B9E-A4BF-4R71-B861-87EF2F394BF9"; 
var guid2 = "E0AE43C5-8FC9-4479-99CC-F70F12BA82C3"; 

if ((formLabel == "New Facility") || (formLabel == "Material Change"))
{
Xrm.Page.data.process.setActiveProcess(guid1, callbackFunction);
}
else if (formLabel == "Non Material Change") {
Xrm.Page.data.process.setActiveProcess(guid2, callbackFunction);

//formContext.data.process.setActiveProcess(guid2, callbackFunction);
}
}
function callbackFunction(result) {
if (result == "success") {

alert(result);
}
else {
alert(result);
}
}

Kindly suggest.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Flydancer Profile Picture
    1,332 on at

    Try removing the small "b" in front of your guid1 which you probably accidentally copied from the URL Box.

  • Community Member Profile Picture
    on at

    Thanks. It was typo mistake, but still it didn't work. 

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi,

    The code is perfectly working fine.

    few things :

    1. Make sure you are calling this code/function on all onload forms and just not one form.

    2. make sure the guid is correct

    3. make sure the label is correct.

    In the end - you can try to debug your script in the browser to see what line is failing.

    function ChangeProcess(executionContext) {
    //debugger;
    var formContext = executionContext.getFormContext();
    var formLabel = formContext.ui.formSelector.getCurrentItem().getLabel();
    var guid1 = "B90B7BFC-A456-440B-BD67-0CA0E823518A"; 
    var guid2 = "3E8EBEE6-A2BC-4451-9C5F-B146B085413A"; 
    
    if ((formLabel == "Opportunity") )
    {
    Xrm.Page.data.process.setActiveProcess(guid1, callbackFunction);
    }
    else if (formLabel == "Project Information") {
    Xrm.Page.data.process.setActiveProcess(guid2, callbackFunction);
    
    //formContext.data.process.setActiveProcess(guid2, callbackFunction);
    }
    }
    function callbackFunction(result) {
    if (result == "success") {
    
    alert(result);
    }
    else {
    alert(result);
    }
    }
  • Community Member Profile Picture
    on at

    Hi, Thanks for the reply.

    The points mentioned by you have already checked.

    All the guid's/labels are correct, Callbackfunction returns "invalid" as output, it should return success.

    I tried the same code in different entity, but it didn't work for the new entity also.

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    I have  not made any changes to your code and it worked flawless in my trial.

    could you please debug the script.

  • gdas Profile Picture
    50,091 Moderator on at

    As per above discussion I think the problem is in below code  -

    Xrm.Page.data.process.setActiveProcess(guid1, callbackFunction);

    Check here old thread might be this helps you -

    community.dynamics.com/.../164769

  • Community Member Profile Picture
    on at

    I removed formExecution from code and used Xrm.Page instead, but still no luck.

    I am calling "ChangeProcess" on onload, I tried in trial instance also but still facing same issue.

  • naresh babu Profile Picture
    425 on at

    Hi,

    Even i am facing same issue. 

    Here i am having only one form with one default business process flow and two custom business process flows.
    Running the javascript (onload and onchange events). When i tried first beofre seven months it was working fine and now ,it is not changing the business process flows(Onload and onchange events).

    Have you solved this issue?
    if yes, Tell me your approach to solve this issue.

  • naresh babu Profile Picture
    425 on at

    I have tried the same query in trail version 1710 (9.1.0.323) online. Its working fine.

    In my client CRM instance, this is not working. In my client Dynamics 365 CRM, online version 1710 (9.1.0.284), I have changed the guards.

    I have bound this script in the onload event of case entity

    function gettypes()
    {
    debugger;
    var activeProcess = Xrm.Page.data.process.getActiveProcess();
    var activeProcessId= activeProcess.getId();
    var activeProcessName= activeProcess.getName();
    if (activeProcess != null)
    {
    if(Xrm.Page.getAttribute('title').getValue() != null)
    {
    var businessProcessProductId="C4CD0E53-5CCB-446B-A43C-6514B5FE5B88";
    //var businessProcessServiceId="7FB897AA-2C6B-4248-953C-47E0925186BB";
    var businessProcessDefaultId="0FFBCDE4-61C1-4355-AA89-AA1D7B2B8792";
    if(activeProcessId.toLowerCase() != businessProcessProductId.toLowerCase())
    {
    Xrm.Page.data.process.setActiveProcess(businessProcessProductId, callbackFunction);
    }
    }
    else {
    Xrm.Page.data.process.setActiveProcess(businessProcessDefaultId, callbackFunction);
    }
    }
    else {
    //Xrm.Page.data.process.setActiveProcess(businessProcessDefaultId, callbackFunction);
    }
    }
    function callbackFunction(response)
    {
    if (response == "success")
    {
    alert("BPF changed !!!");
    }
    else
    {
    alert("Error changing BPF!!!");
    }
    }


    javascript is not working for 3 bpfs(1 default and 2 custom bpf) 

    Onchange and onload events.
    for me, Callbackfunction is "invalid"

    The above query was updated with another new bpf id.

    My script is:-

    function gettypes()
    {
    debugger;
    var activeProcess = Xrm.Page.data.process.getActiveProcess();
    var activeProcessId= activeProcess.getId();
    var activeProcessName= activeProcess.getName();
    if (activeProcess != null)
    {
    if(Xrm.Page.getAttribute('title').getValue() != null)
    {
    var businessProcessProductId="C4CD0E53-5CCB-446B-A43C-6514B5FE5B88";
    var businessProcessServiceId="066FCE70-722F-469C-811A-55A77BBA0B6C";
    var businessProcessDefaultId="0FFBCDE4-61C1-4355-AA89-AA1D7B2B8792";
    if(activeProcessId.toLowerCase() != businessProcessProductId.toLowerCase())
    {
    Xrm.Page.data.process.setActiveProcess(businessProcessProductId, callbackFunction);
    }
    }
    else {
    Xrm.Page.data.process.setActiveProcess(businessProcessServiceId, callbackFunction);
    }
    }
    else {
    //Xrm.Page.data.process.setActiveProcess(businessProcessDefaultId, callbackFunction);
    }
    }
    function callbackFunction(response)
    {
    if (response == "success")
    {
    alert("BPF changed !!!");
    }
    else
    {
    alert("Error changing BPF!!!");
    }
    }

     

  • Community Member Profile Picture
    on at

    Even I am having same instance with version Version 1710 (9.1.0.2842) online. No resolution found yet.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans