Hello! I'm trying to make a plugin to insert the firstname, middlename, and lastname from a prospect into my database using a web service after an opportunity is created, but I do not know how to get the prospect information from an opportunity plugin.
If I assign entity["name"].ToString(); to a variable, it returns the name of the Opportunity, but if I assign entity["originatingleadid"].ToString(); it returns "Microsoft.Xrm.Sdk.EntityReference".
Then, after the information is inserted in the database, my web service returns an ID. How can I save this Id in an Opportunity field?
Here's the code of my plugin.
Thanks in advance.
public void Execute(IServiceProvider serviceProvider) { 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) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "opportunity") return; nom = entity["name"].ToString(); app = entity["originatingleadid"].ToString(); apm = entity["ownerid"].ToString(); crmPlugins.crmPlugInsert.WebReference.websCRM webService = new crmPlugins.crmPlugInsert.WebReference.websCRM(); folioS = webService.Insert(nom, app, apm); } }
*This post is locked for comments