CRM 2016: Selected stage and highlighted stage is not same when stageid is set via plugin

this is just a copy past of the website
https://meghshyam.wordpress.com/2017/09/27/crm-2016-selected-stage-and-highlighted-stage-is-not-same-when-stageid-is-set-via-plugin/

Faced the weird error in Business process flow in CRM 2016 version.

Scenario is when we move the business process stage programmatically via plugin by setting thestageid field, you will find a weird behaviour where BPF is still showing the existing stage as highlighted however the active stage is set to correct stage i.e. next stage.

After googling some blogs (link)proposed some javascript methods like Xrm.Page.data.process.addOnStageSelected(stageSelected) but that don’t really help as this is specific to client side scripting. Then the next hope was to dig into the entity fields and find out if there is any hidden field which is storing the selected stage value for that respective record and here I got the reference.


In CRM 2016 (not sure about CRM 2015), there is field called “TraversedPath” which stores the guid’s of BPF stageid when moved manually.

For ex. If you have 8 stages on BPF and you move the stage manually uptill stage 3 then this field “traversedpath” will capture the each moved stageid in a sequence (comma separated). And if you have some requirement to move the BPF stage from 3rd to 4thprogramatically you have to update this “traversedpath” field within the plugin itself like


//Fetch the traversedpath field value from the Preimage object

string traversedpath = PreImage.Attributes[“traversedpath”].ToString();

if (traversedpath != “”)

{

traversedpath += “,” + Stageid.ToString().Replace(“{“,””).Replace(“}”, “”);

Entity updateEntity = new Entity(“opportunity”);

updateEntity.Id = entity.Id;

updateEntity [“traversedpath”] = traversedpath;

service.Update(updateEntity);

}

And that’s it. Hope it helps somebody.

Commentaires

Posts les plus consultés de ce blog

CRM dynamics V9 wait Async web API to contiue code

Decode/render HTML from a field in crm dynamics