locked
Triggering plugin with change of Business Process stage RRS feed

  • Question

  • Hi All,

    Can I trigger a plug-in when a business processes stage is changed.

    My requirement is: I want a plug-in to fire when I click on Next Stage of business process. Is it possible. If so how?

    Thanks in Advance.


    Jugal Kishore Dandamudi.

    Friday, March 27, 2015 1:21 PM

Answers

  • But, we figured a solution for it.

    I wrote a script to update a field with the corresponding stage name, and triggering plugin on the that fields update.

    I don't how far that is suggest-able. Any better solutions are accepted.


    Jugal Kishore Dandamudi.

    Monday, March 30, 2015 12:52 PM

All replies

  • Hello Jugal,

    Try registering your plugin on the update of a field called "stepname". This field contains information about the name of the stage your opportunity is at: "1-Qualify", "2-Develop", etc.

    Monday, March 30, 2015 8:42 AM
  • Hi Pedro,

    I'm afraid I couldn't see any field with name "stepname" in plug-in registration tool. I'm I missing something?


    Jugal Kishore Dandamudi.

    Monday, March 30, 2015 12:50 PM
  • But, we figured a solution for it.

    I wrote a script to update a field with the corresponding stage name, and triggering plugin on the that fields update.

    I don't how far that is suggest-able. Any better solutions are accepted.


    Jugal Kishore Dandamudi.

    Monday, March 30, 2015 12:52 PM
  • Pedro is correct, stepname (Display name = Pipeline Phase) does get updated when the user moves between stages but ONLY if you assign a 'Stage Category' to each stage within your business process flow.


    MCTS. GAP Consulting Ltd. Microsoft Community Contributor Award 2011 & 2013

    Monday, March 30, 2015 10:17 PM
    Answerer
  • Hi Rob,

    Thanks for reply.

    So, which way do you suggest in order to achieve "assign a 'Stage Category' to each stage within your business process flow".


    Jugal Kishore Dandamudi.

    Tuesday, March 31, 2015 5:54 AM
  • Jugal,

    I managed to achieve what you want to do in a pre-operation plugin.

    Register the plugin on the update of the entity on which the Business Proces Flow is defined. Do not filter on the update of specific attributes! If you try to do that, you will notice that the StageId field is not available.

    However, in the plugin execution context, the value of the StageId is present if you change from 1 stage to another.

    Then you can write your plugin code, based on the presence of the StageId in the "Target" Inputparameter.

    See code below : it is my test code and it works.

    Cheers,

    Tom Van Hecke

    namespace Xmon.CrmCustomizations.Plugin
    {
        public class ValidateTestBPFChange : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                var manager = new ManagerBase(serviceProvider, true);

                if (manager.PluginExecutionContext.InputParameters.Contains("Target"))
                {
                    Entity currentEntity = (Entity)manager.PluginExecutionContext.InputParameters["Target"];

                    string message = string.Empty;

                    currentEntity.Attributes.ToList().ForEach(att => message += (att.Key + " | "));
                    if (currentEntity.Contains("stageid")){
                        Guid stageId = (Guid)currentEntity["stageid"];
                        if (stageId == Guid.Parse("A241CA9B-6193-1132-BAEB-CD05BEC8D5D5"))
                            throw new Exception("Second");
                    }
                }
                else
                    throw new Exception("Parameter not retrieved!");

            }
        }
    }

    Wednesday, June 3, 2015 12:44 PM
  • if (currentEntity.Contains("stageid")) will trigger in all stages but if we need to trigger on a particular stage only, what could be the solution without hardcoding the values?
    Monday, July 3, 2017 6:35 AM