Thursday, October 31, 2013

Actions: usage of input/output arguments in plugins that handle Actions

Main message is that input/output arguments are available in InputParameters/OutputParameters collections of PluginExecutionContext.

Usage of Input argument
Following code shows how to check that Input Argument was passed and get value:

if (localContext.PluginExecutionContext.InputParameters.Contains("ArgumentName"))
{
    string stringInputArgument = (string)localContext.PluginExecutionContext.InputParameters["ArgumentName"];
}
else
{
    //Your code for case when Argument was not passed
}

Usage of Output argument
Following code shows how to set Output argument:

localContext.PluginExecutionContext.OutputParameters["OutputArgumentName"] = <Value>;

One thing you should remember is that step that handles your action and sets Output arguments had to be registered on Post Operation (40).

For those who use CRM Developer Toolkit – registration of new plugin, registration of your step in code of your plugin and part of RegisterFile.crmregister file:


base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, 
    "MessageName", null, new Action<LocalPluginContext>(PluginClass)));

<Step CustomConfiguration="" Name="StepName" Description="Description" Id="024c3b93-6041-e311-ad38-6c3be5a8d218" 
    MessageName="MessageName" Mode="Synchronous" PrimaryEntityName="none" Rank="1" SecureConfiguration="" 
    Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">

For those who use PluginRegistration tool:

No comments:

Post a Comment