im new in CRM. I have create two entity : Order and Product. On order entity there is look up field that fire to product entity. I try to get productquantity from product through look up field and paste it to a field within the order entity. Here is the code i tried:
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Attributes.Contains("new_productname"))
{
Entity productreference = service.Retrieve("new_callistyproduct", ((EntityReference)entity["new_productname"]).Id, new ColumnSet(true));
if (productreference.Attributes.Contains("new_productquantity"))
{
if (entity.Attributes.Contains("new_numberofproduct"))
entity["new_numberofproduct"] = productreference.GetAttributeValue<Decimal>("new_productquantity");
else
entity.Attributes.Add("new_numberofproduct", productreference.GetAttributeValue<Decimal>("new_productquantity"));
}
}
}
I want this plugin work whenever i create a new record. So i register this plugin as Pre-create event. But, when i try to create a record. This plugin did't retrieve value from productquantity field. So, i tried to run this plugin as Pre-Update event. On the record i've create before, i change the lookup value from product A to product B. And its work, the plugin retrieve a product quantity value from product B.
The question is, what should i do if i want this plugin also work for pre-Create event.
Thanks
new_productname
filled when the plugin is triggered in the pre-operation create stage? – Henk van Boeijen