Update Dynamic Properties of Product (Product Properties) in Dynamics CRM/365 – C#
May 9, 2017 Leave a comment
Its a two step process to update Dynamic Properties of Product (Sales Order Product) Or Product Properties of your sales order.
- Query “dynamicpropertyinstance” entity by “regardingobjectid” – here, your regardingobjectid will be your salesorderdetailid.
- By querying crm, you will retrieve all properties for that sales order product. Here in my example case, TestProperty-Age and TestProperty-Sex
- Run the loop for all rows inside your retrieved Entity Collection, set the desired values and call update method.
Example CRM UI:
Please see C# script below:
public void goCreateObject(IOrganizationService service) { QueryExpression objQueryExp = new QueryExpression(); objQueryExp.EntityName = "dynamicpropertyinstance"; objQueryExp.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, "5b8ff2cb-b533-e711-8113-e0071b668xxx")); objQueryExp.ColumnSet = new ColumnSet(true); EntityCollection entColDynamicProperties = service.RetrieveMultiple(objQueryExp); try { foreach (Entity entity in entColDynamicProperties.Entities) { if (((EntityReference)entity.Attributes("dynamicpropertyid")).Name.Contains("TestProperty-Age")) { entity.Attributes("valueinteger") = Convert.ToInt32(99); } if (((EntityReference)entity.Attributes("dynamicpropertyid")).Name.Contains("TestProperty-Sex")) { entity.Attributes("valueinteger") = Convert.ToInt32(1); } service.Update(entity); } Interaction.MsgBox("Success"); } catch (Exception ex) { Interaction.MsgBox("Exception! " + ex.StackTrace); } }