Hiii guys, i have 2 entities: Product and order. There is product quantity field in product entity. Whenever order record created, the product quantity will be reduced based on the selected product.
Im able to reduced product quantity when order record is created. Now i want to increase product quantity value whenever order records are deleted.
This what i have done so far:
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 EntityReference)
{
EntityReference entityreference = (EntityReference)context.InputParameters["Target"];
if (context.MessageName == "Delete")
{
Entity ent = service.Retrieve(entityreference.LogicalName, entityreference.Id, new ColumnSet(true));
var number = ent.GetAttributeValue<Decimal>("new_jumlahunit");
var sisaunit = number + 1;
ent.Attributes["new_jumlahunit"] = sisaunit;
service.Update(ent);
}
}
}
i register this plugin on : pre-operation. But i got this error message: "The specified field does not exist in Microsoft Dynamics CRM"
*This post is locked for comments
I have the same question (0)