I'm migrating from CRM 2015 to Dynamics 365 and there is a web resource that has code breaking which is:
var stageID = Xrm.Page.data.process.getActiveStage().getId();
I'm trying something like this to update the code, but the following still doesn't work:
var formContext = executionObj.getFormContext(); var stageObject = formContext.data.process.getActiveStage();
The stage object is always null, so of course I can't try to get its ID.
Please see my answer, the syntax I provided is the replacement for the deprecated “Xrm.page…” way, thanks.
To get the Stage ID in a Dynamics 365 Web Resource, you can use the Xrm.Page.data.process API. This API provides methods and properties for working with business processes and the stages within those processes. To get the Stage ID, you can use the getActiveStage method, which returns an object that contains information about the current stage, including the Stage ID. Here is an example of how to use this method:
var stage = Xrm.Page.data.process.getActiveStage();
var stageId = stage.getId();
Once you have the Stage ID, you can use it to perform operations on the stage, such as moving to the next stage in the process or completing the stage.
It was discovered after all the JS was fixed by first checking the stage object (from formContext.data.process.getActiveStage()) is not null, b/c if you try to getID() with a null stage object Dynamics will throw a script error.
After the fix was applied, the form finally would load correctly but still the BPF wasn't showing on top.
The BPF showed correctly on the form by configuring in general settings this option:
Stay up to date on forum activity by subscribing.
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156