Hello! I'm trying to make a plugin to insert the firstname, middlename, and lastname into my database after an opportunity is created using a web service, but I do not know how to get that 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)); // Obtain the execution context from the service provider.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); // Obtain the organization service reference.
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 = "Jerry";
//app = "Seinfeld";
//apm = "Costanza";
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);
}
}






