CRM 2013 – Update the Business Process and Stage dynamically

If you wish to update the Business Process Flow stage of any entity in a workflow, its not immediately obvious how to do it. Develop1 have a fantastic Custom Workflow Activity that does the job.

With a few tweaks, a similar activity can update the BPF stage of an entity ‘created’ during the workflow process.

Add an InArgument of type EntityReference to the Activity, you need to specify what type of entity the reference will refer to.

[Input(“Related Opportunity”)]
public InArgument RelatedOpportunity { get; set; }

Then use it in the activity like any other EntityReference type.

Entity updatedStage = new Entity(context.PrimaryEntityName);
updatedStage.Id = RelatedOpportunity.Get(executionContext).Id;
updatedStage[“stageid”] = stage.ProcessStageId;
updatedStage[“processid”] = process.WorkflowId;

Get the Develop1 Custom Workflow Activity here