I need to get the value of a text field from the opportunity to opportunity product. I'm use D365
I tried to make a plugin but it turns out that it does not throw any errors and does not copy the value of the text field
the field name in opportunity is: bzg_companyname
the field name in opportuniryproduct is: bzg_companyname
this is the code
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Entity Opportunity = new Entity("opportunity");
if ((context.InputParameters.Contains("Target")) && (context.InputParameters["Target"] is Entity))
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "oportunityproduct")
return;
try
{
if (entity.Contains("opportunityid"))
{
Opportunity.Id = ((EntityReference)entity["opportunityid"]).Id;
Opportunity["bzg_companynameforurl"] = entity.Contains("bzg_companynameforurl") ? entity["bzg_companynameforurl"].ToString() : string.Empty;
service.Update(entity);
}
}
catch (InvalidPluginExecutionException ex)
{
throw ex;
}
}
}
Please, I'm not a full developer, so can you suggest me any solution, could be a plugin or not