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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Switch Business process flow based on the form with JS Keep on refreshing the page

(0) ShareShare
ReportReport
Posted on by 30

Hi,

We added the code in the form to change the business process flow based on form name with javascript on load event of the form. After adding the script , form kept on refreshing in loop. But we did not have loop or any refresh code.

Any help will be appreciated !!!

Thanks,

Mey

I have the same question (0)
  • Suggested answer
    Satish Tiwari - CRM Profile Picture
    5,400 on at

    Hello Mey,

    If you use the network trace (F12 debugger), do you see any error / warning or any information when the issue happens ?

  • Dynamics 365 Portal Profile Picture
    30 on at

    I did not get any error relevant to this issue. In the network, it looks like it is running first time and set the process flow and second time run , it gives script error.

    Below is the code I'm using currently

    Now , it runs and gives error on getid. "Cannot read property 'getId' of null"

    function onload(executionContext) {

       var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

    var formContext = executionContext.getFormContext();

    var activeProcessID = formContext.data.process.getActiveProcess().getId();

    alert(activeProcessID );

       var flow1= "guid1";

       var flow2= "guid2";

       if (formName == "form1" && activeProcessID.toUpperCase() !=flow1) {

       alert('change process flow');

               formContext.data.process.setActiveProcess(flow1, callBackFunction);

              formContext.data.save();

       }

       else if(formName == "form2" && activeProcessID.toUpperCase() !=flow2) {

              alert('change process flow');

               formContext.data.process.setActiveProcess(flow2, callBackFunction);

               formContext.data.save();

       }

    };

    function callBackFunction(result) {

       if (result == "success") { } else { }

    }

  • Suggested answer
    Satish Tiwari - CRM Profile Picture
    5,400 on at

    You may want to remove this line -  var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel(); as Xrm.page has been deprecated and instead of using formName, you can use formType, something like this -

    var formContext = executionContext.getFormContext();
    var formType = formContext.ui.getFormType();
    var activeProcessID = formContext.data.process.getActiveProcess().getId();
    if ( formType == 2 && activeProcessID.toUpperCase() !="GUID")
    {
    formContext.data.process.setActiveProcess("GUID", callBackFunction);
    }

    You can find more details here about deprecation here - https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated

  • Dynamics 365 Portal Profile Picture
    30 on at

    getting error in console

  • Suggested answer
    Satish Tiwari - CRM Profile Picture
    5,400 on at

    Is it same or different error ?

  • Dynamics 365 Portal Profile Picture
    30 on at

    This is the different error occuring in the console. Not sure why the form is kept on executing the javascript which is in onload event.

  • Suggested answer
    Satish Tiwari - CRM Profile Picture
    5,400 on at

    Can you share the error ?

  • Dynamics 365 Portal Profile Picture
    30 on at

    To make it very simple,  

    If I add the below code inside the onload event , it triggers the onload event twice. This is causing all the problems. If we get to know why the onload event triggered twice , we can resolve the issues.

    formContext.data.process.setActiveProcess(DemoFlow, callBackFunction);

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

News and Announcements

[Smoke test 2510.1]

Quick Links

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans