MS Dynamics 365- Custom action - Read input parameter values from plugin

Ankaprasad
Posted by Ankaprasad under C# category on | Points: 40 | Views : 348
Below is the sample code to access input parameter value from custom action to pluign

          int status = Convert.ToInt32(context.InputParameters["statusReason"]);
string id = context.InputParameters["id"].ToString();


Below is the detailed plugin sample code

 public class CloseQuote: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{

IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IOrganizationServiceFactory factory =(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

try
{
if (context.InputParameters != null)
{
int status = Convert.ToInt32(context.InputParameters["statusReason"]);
string id = context.InputParameters["id"].ToString();


trace.Trace(id.ToString());
trace.Trace(status.ToString());

Entity party = new Entity("quote", new Guid(id));
party["statecode"] = new OptionSetValue(1); // status - Active
party["statuscode"] = new OptionSetValue(2); // status Reason - inprogress
service.Update(party);

CloseQuoteRequest req = new CloseQuoteRequest();
Entity quoteClose = new Entity("quoteclose");
quoteClose.Attributes.Add("quoteid", new EntityReference("quote", new Guid(id)));
// quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
req.QuoteClose = quoteClose;
req.RequestName = "CloseQuote";
OptionSetValue o = new OptionSetValue();
o.Value = status;
req.Status = o;

CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);


}
}
catch (Exception ex)
{
trace.Trace("Error : " +ex.Message);
//throw;
}

}
}

Comments or Responses

Login to post response