Hi experts.
I am currently working on a project that intends to set product data in CRM, using our ERP database as a source.
Querying ERP and getting the correct data into c# is no problem.
Setting CRM product fields "name" and "price" has also succeeded.
I know want to expand the data transfer to the fields currentcost and standardcost for entity product. However, I am getting "Object reference not set to an instance of an object".
Here is a bit of code i use:
QueryExpression qe = new QueryExpression();
qe.EntityName = "productpricelevel";
qe.ColumnSet = new ColumnSet();
qe.ColumnSet.Columns.Add("amount");
qe.ColumnSet.Columns.Add("productid");
qe.ColumnSet.Columns.Add("pricelevelid");
EntityCollection ec = ct.RetrieveMultiple(qe);
foreach (Entity act in ec.Entities) {
EntityReference reference = (EntityReference)act["productid"];
Entity prodEntity = ct.Retrieve(reference.LogicalName, reference.Id, new ColumnSet("productid", "productnumber", "price", "name", "currentcost", "standardcost"));
//The following line is working fine:
prodEntity.GetAttributeValue<Money>("price").Value = decimal.Parse(glListPrice);
//the next line is NOT:
prodEntity.GetAttributeValue<Money>("currentcost").Value = decimal.Parse(glListPrice);
}
ct.update(prodEntity);
I am almost certain the queryexpression "qe" isn't retrieving the currentcost field, but how can I convince it to retrieve it?
Thanks