// based on Starter Execution Method ////// Return the opportunity id /// /// Plugin context///opportunityid public string GetEntityId(IPluginExecutionContext context) { string opportunityid = ""; DynamicEntity opportunityClose = null; switch (context.MessageName) { case "Create": if (context.OutputParameters.Properties.Contains("id")) { opportunityid = context.OutputParameters.Properties["id"].ToString(); } break; case "Update": if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity) { DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target]; opportunityid = ((Key)entity.Properties["opportunityid"]).Value.ToString(); } break; case "SetState": if (context.InputParameters.Properties.Contains("EntityMoniker")) { if (context.InputParameters.Properties.Contains("State")) { Moniker entityMoniker = (Moniker)context.InputParameters.Properties[ParameterName.EntityMoniker]; opportunityid = entityMoniker.Id.ToString(); } } break; case "SetStateDynamicEntity": if (context.InputParameters.Properties.Contains("EntityMoniker")) { if (context.InputParameters.Properties.Contains("State")) { Moniker entityMoniker = (Moniker)context.InputParameters.Properties[ParameterName.EntityMoniker]; opportunityid = entityMoniker.Id.ToString(); } } break; case "Win": opportunityClose = (DynamicEntity)context.InputParameters["OpportunityClose"]; Lookup WonLook = (Lookup)opportunityClose.Properties["opportunityid"]; opportunityid = WonLook.Value.ToString(); break; case "Lose": opportunityClose = (DynamicEntity)context.InputParameters["OpportunityClose"]; Lookup LoseLook = (Lookup)opportunityClose.Properties["opportunityid"]; opportunityid = LoseLook.Value.ToString(); break; case "Assign": if (context.InputParameters.Properties.Contains("Assignee") && context.InputParameters.Properties["Assignee"] is SecurityPrincipal) { Moniker assignEntity = (Moniker)context.InputParameters.Properties["Target"]; opportunityid = assignEntity.Id.ToString(); } break; case "Delete": if (context.InputParameters.Properties.Contains("Target")) { Moniker entityMoniker = null; entityMoniker = (Moniker)context.InputParameters.Properties[ParameterName.Target]; opportunityid = entityMoniker.Id.ToString(); } break; } return opportunityid; }
2008-09-17
Plugin's Starter Execution Method
Have found excellent method at David Fronk blog Starter Execution Method and slightly update it in to separate method.
Ярлыки:
message,
plug-in,
sample code
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий