Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

Posted on by Microsoft Employee

On the custom entity I have business process flow and plugin on an update.
I would like to obtain actual StageName. I have written code which is getting me only previous StagName.
E.g. I have phase 1,2,3,4. I am in phase 1 and click on button "next phase" this code can not identify that
I am in phase 2, but show me again phase 1.
Is there any solution how to identify previous and actual phase name on plugin? Below you can find my code.

string actualstagename = "";

RetrieveProcessInstancesRequest retrieveProcessInstancesRequest = new RetrieveProcessInstancesRequest
{
EntityId = EntityGuid,
EntityLogicalName = "new_customentity"
};
RetrieveProcessInstancesResponse retrieveProcessInstancesResponse =
(RetrieveProcessInstancesResponse)service.Execute(retrieveProcessInstancesRequest);
Guid activeProcessInstaceId = new Guid(retrieveProcessInstancesResponse.Processes.Entities[0].Id.ToString());
EntityReference workflowReference =
(EntityReference)retrieveProcessInstancesResponse.Processes.Entities[0].Attributes["processid"];
Entity curenttestprocesss = service.Retrieve("new_bpf_" + workflowReference.Id.ToString().Replace("-", ""), activeProcessInstaceId, new ColumnSet(true));
RetrieveActivePathRequest retrieveActivePathRequest = new RetrieveActivePathRequest
{
ProcessInstanceId = activeProcessInstaceId
};

RetrieveActivePathResponse retrieveActivePathResponse =
(RetrieveActivePathResponse)service.Execute(retrieveActivePathRequest);

foreach (var processStage in retrieveActivePathResponse.ProcessStages.Entities)
{
TracingService.Trace("T9 " + ((EntityReference)curenttestprocesss["activestageid"]).Id.ToString());
TracingService.Trace("T10 "+ processStage["processstageid"].ToString());

if (((EntityReference)curenttestprocesss["activestageid"]).Id.ToString() == processStage["processstageid"].ToString())
{

actualstagename = processStage["stagename"].ToString();
}
}

TracingService.Trace("StageName: " + actualstagename);

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    2 line was only because I changed too many time my code. I will use 1 line finally. Thank you for help :-)

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Hey,

    Great :)

    Just to know, why two conditions when you know it is 2

    why not?

     if (PluginExecutionContext.Depth != 2)

                  return;

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Hey,

    Great :)

    Just to know, why two condition if you know it is 2

    why not?

     if (PluginExecutionContext.Depth != 2)

                  return;

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    I resolved this issue, I put to my plugin this code:

               if (PluginExecutionContext.Depth > 2)

                   return;

               if (PluginExecutionContext.Depth == 1)

                   return;

    This mean, plugin on depth value 2 will get correct actual StageName. This depth can change sequence.

    Execution order on plugin I set to value 1.

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Hi,

    Async should work otherwise you have share more details for any further thought process.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    This solution can works, but on plugin I have too many other implementation, where I dont use BPF. I need use trigger on my custom entity.

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Hi,

    Then you can achieve this by triggering your plugin on BPF entity Active stage field update

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Plugin is called before update BPF record related to my entity. I tryed set execution order on plugin to value 10 and this not help. I have too much logic based on moving phase on plugin. If i will use advance find, I get correct stage 2. So moving working correctly.

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Plugin - get actual and previous Stage Name (Microsoft Dynamics 9)

    Hi,

    Did you try seeing BPF record manually from advance find and its showing right stage? then try retrieving BPF entity directly. you can get the field names and entity name form advance find fetch query.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans