I want to make a plugin that inserts into my database the prospect's name after the Opportunity is created, and then save into the opportunity notes the id returned by my web service.
I managed to create and deploy a plugin to insert from a web service, but I do not know how get the data I want, and save the returned id. Can you help me?
Here's my code with dummy data to test the web service functionality, it inserts into my database after the opportunity is saved.
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)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an opportunity.
if (entity.LogicalName != "opportunity")
return;
nom = "Jerry";
app = "Seinfeld";
apm = "Costanza";
crmPlugins.crmPlugInsert.WebReference.websCRM webService = new crmPlugins.crmPlugInsert.WebReference.websCRM();
folioS = webService.Insert(nom, app, apm);
}
}