Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get the current stage ID and stage Name

(0) ShareShare
ReportReport
Posted on by

Hi Expert,

i have a requirement to manipulate the field based on the Business Process Flow stage. Any ideas how to get stageid and stage name?

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: How to get the current stage ID and stage Name

    Hi Barry Francis,

    as told by the community member, the process id and stage id are going deprecated soon, so i don't think this fit to my requirement. But anyways , Thanks for the reply, I truly appreciate.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to get the current stage ID and stage Name

    Hi CRM Newbie 2018,

    Those two fields are not available for use via basic workflow or advanced find (filters), but are visible via Advanced find columns for export and re-import. so it depends what method you want to use to get those two fields.

    You can use JScript variables to get the ID's of the business process flows OnLoad or OnChange of the field; for example:

    var ProcessID = Xrm.Page.getAttribute(“processid”).getValue();

    var StageID = Xrm.Page.getAttribute(“stageid”).getValue();

    Once you have the stage ID's, you can set IF statements to set the stage name based on the ID's of the stages. (If you need to see what the stage ID's are, you can get them from Advanced Find by adding these columns into the view).

    You can also use C# to get these fields via custom workflow and use them to push through the stage names and ID's.

    First, request the input parameter (if its case, then request cases, if its opportunity, request opportunities):

           [RequiredArgument]

           [Input("Case")]

           [ReferenceTarget("incident")]

           public InArgument<EntityReference> Case { get; set; }

    Once you have the input, you can pass it through as the current context and grad the fields from it:

    EntityReference CaseEntity = this.Case.Get(executionContext);

    Entity CaseEntityRef = service.Retrieve(CaseEntity.LogicalName, CaseEntity.Id, new ColumnSet("stageid", "processid"));

    Once you have the fields, you can set these fields into the same entity as an update OR use variables to set the stage names.

    If you only need a view on the stage, then create the system/personal view and use the relational Process Stage(Process Stage) entity to bring through the Process stage name and stage category columns. You can, as discussed earlier, bring through the Stage ID's from the primary entity you are using and use them to match to the stage names.

    Once you have a view, you can use export for re-import to update the fields if its a once off requirement.

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How to get the current stage ID and stage Name

    Hi,

    Try to use the code below.

    var activeStageId, activeStageName;
    //Get the current active stage of the process var activeStage = Xrm.Page.data.process.getActiveStage();
    //Get the ID of the current stage activeStageId = activeStage.getId();
    //Get the Name of the current stage activeStageName= activeStage.getName();

    See: https://adisys.wordpress.com/2017/01/03/dynamics-crm-scripting-for-business-process-flows/

    Hope this helps.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How to get the current stage ID and stage Name

    Hi,

    Refer this fro JS: msdn.microsoft.com/.../dn817878.aspx

    For C#: you can download this sample code code.msdn.microsoft.com/Work-with-business-process-853a5766

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: How to get the current stage ID and stage Name

    Hi ,

    Before Dynamics 365, you can use below code to get the StageID

    var stageID = Xrm.Page.getAttribute(“stageid”).getValue();

    But, with Dynamics 365, the stageID is going to deprecated, so please do not use it. You can refer to below post.

    https://blogs.msdn.microsoft.com/crm/2017/07/30/how-to-determine-which-business-process-flow-bpf-instance-is-shown-when-a-record-is-opened-2/

    So use the below code

    function formonload()
    {
    Xrm.Page.data.process.addOnStageChange(getStage); // Trigger the function when move to next stage.
    getStage();
    }

    function getStage()
    {
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageId = activeStage.getId();
    var stagename = activeStage.getName();
    }

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans