Skip to main content
Dynamics 365 Release Wave Forum
Suggested answer

How to get Stage ID in Dynamics 365 Web Resource?

editSubscribe (0) ShareShare
ReportReport
Posted on by

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.

Attachments
  • How to get Stage ID in Dynamics 365 Web Resource?
    Use my following code get the Stage ID in a Dynamics 365 Web Resource in Dynamics 365
     
    var stageObject = executionObj.getFormContext().data.process.getActiveStage();
    var stageId = stageObject?.getId();
     
    You must check if the stageObject is not null before trying to get its ID, otherwise you will get a script error.
     
  • Summers Profile Picture
    Summers on at
    RE: How to get Stage ID in Dynamics 365 Web Resource?

    Please see my answer, the syntax I provided is the replacement for the deprecated “Xrm.page…” way, thanks.

  • Walpha Profile Picture
    Walpha on at
    RE: How to get Stage ID in Dynamics 365 Web Resource?

    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.

  • Suggested answer
    Summers Profile Picture
    Summers on at
    RE: How to get Stage ID in Dynamics 365 Web Resource?

    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:

    pastedimage1670343532649v1.png

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Featured topics

Product updates

Dynamics 365 release plans