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
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.
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.
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.
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
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.
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();
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156