SBX - Search With Button

SBX - Forum Post Title

How to get the current stage ID and stage Name

Microsoft Dynamics CRM Forum

Bury asked a question on 5 Feb 2018 1:13 AM

Question Status

Verified

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?

Reply
Wei Jie Fun responded on 5 Feb 2018 1:16 AM
Verified Answer

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();
}

Reply
Ravi Kashyap responded on 5 Feb 2018 1:17 AM
Verified Answer

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

Reply
Nithya Gopinath responded on 5 Feb 2018 1:48 AM
My Badges
Verified Answer

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.

Reply
Barry Francis responded on 3 May 2018 10:09 AM
My Badges
Suggested Answer

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.

Reply
Bury responded on 3 May 2018 10:17 AM

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.

Reply
Wei Jie Fun responded on 5 Feb 2018 1:16 AM
Verified Answer

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();
}

Reply
Ravi Kashyap responded on 5 Feb 2018 1:17 AM
Verified Answer

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

Reply
Nithya Gopinath responded on 5 Feb 2018 1:48 AM
My Badges
Verified Answer

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.

Reply
Barry Francis responded on 3 May 2018 10:09 AM
My Badges
Suggested Answer

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.

Reply

SBX - Two Col Forum

SBX - Migrated JS