Answered by:
MS CRM 2013 Plugin issue

Question
-
Hi All
Plugin Inputparameter context not working. Code is below.
IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));IOrganizationServiceFactory serviceFactory =(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
throw new InvalidPluginExecutionException("work");
}
else { throw new InvalidPluginExecutionException("not work"); }going to else condition i.e,. "not work".
I have registered plugin on 'QualifyLead' message for Lead entity at pre-validation stage.
and throw new exception is also not working.
Please Help.
Friday, December 27, 2013 9:53 AM
Answers
-
Hi,
Maybe "Target" is not a valid input parameter. Try to get
EntityReference _targetReference = (EntityReference)context.InputParameters["LeadId"]; Entity _target = service.Retrieve("lead", leadid.Id, new ColumnSet(true));
steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at- Proposed as answer by Guido PreiteMVP Friday, December 27, 2013 10:04 AM
- Marked as answer by Suresh Sorde Friday, December 27, 2013 10:29 AM
Friday, December 27, 2013 10:01 AM -
The QualifyLead message doesn't contain "Target" but "LeadId", you can check this sample code:
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("LeadId") && context.InputParameters["LeadId"] is EntityReference) { EntityReference leadReference = (EntityReference)context.InputParameters["LeadId"]; Guid leadId = leadReference.Id; // rest of your code
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Friday, December 27, 2013 10:03 AM
- Marked as answer by Suresh Sorde Friday, December 27, 2013 10:29 AM
Friday, December 27, 2013 10:03 AM
All replies
-
Hi,
Maybe "Target" is not a valid input parameter. Try to get
EntityReference _targetReference = (EntityReference)context.InputParameters["LeadId"]; Entity _target = service.Retrieve("lead", leadid.Id, new ColumnSet(true));
steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at- Proposed as answer by Guido PreiteMVP Friday, December 27, 2013 10:04 AM
- Marked as answer by Suresh Sorde Friday, December 27, 2013 10:29 AM
Friday, December 27, 2013 10:01 AM -
The QualifyLead message doesn't contain "Target" but "LeadId", you can check this sample code:
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("LeadId") && context.InputParameters["LeadId"] is EntityReference) { EntityReference leadReference = (EntityReference)context.InputParameters["LeadId"]; Guid leadId = leadReference.Id; // rest of your code
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Guido PreiteMVP Friday, December 27, 2013 10:03 AM
- Marked as answer by Suresh Sorde Friday, December 27, 2013 10:29 AM
Friday, December 27, 2013 10:03 AM -
Thanks Steve and Guido..
Its working..
Friday, December 27, 2013 10:30 AM