Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to get the current stage ID and stage Name

Posted on by Microsoft Employee

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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Nithya Gopinath 17,074 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
    RaviKashyap 55,410 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
    Alex Fun Wei Jie 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans