2009-11-13

Passing parameters between MS CRM plugins

I was needed to pass a variable from one plugin to another. If you have a two plugin at pre and post stage registered for on entity, then you can use a SharedVariables context property. But, if every plugins is a different assembly, and they are registered for a different entities... So, when the first plugin is firing, the second, which is starting after that, needed to know some information for redirecting it logic to another way.

I had created some common assembly with helper methods and called it "Helper". Then I had created a static class with static variable and had put the value into it, at the first plugin execution runtime. In the second plugin I just get the value from the static common variable.

And nothing about read\write DB operations.
Helper assembly.
namespace Helper
{
    public static class Keeper
    {
        private static bool _UpdateOppAfterHistory = true;
        public static bool UpdateOppAfterHistory 
        {
            get { return _UpdateOppAfterHistory; }
            set { _UpdateOppAfterHistory = value; }
        }
        
    }
    public class OpportunityHelper
    { ... }
}

First firing plugin code
Keeper.UpdateOppAfterHistory = false;

OpportunityHelper.CreateOpportunityHistory(Opp,crmService);
                
// removing the flag to the back
Keeper.UpdateOppAfterHistory = true;

Second firing plugin code
// common shared variable analysis
bool UpdateOppAfterHistory = Keeper.UpdateOppAfterHistory;
if (UpdateOppAfterHistory)
{ ... }

Комментариев нет: