Hi All,
I am facing some difficulty while developing a plugin to update a value.
I am fetching value of pricelist from respective opportunity entity on creation of opportunity product.
I am using another query to find the discount details of pricelist using the value of pricelist retrieved from previous query. I have written the following code:
string parentOpportunity = ((EntityReference)e.Attributes["opportunityid"]).Name;
QueryExpression query = new QueryExpression("opportunity");
ColumnSet columns = new ColumnSet("pricelevelid", "name");
query.ColumnSet = columns;
query.Criteria.AddCondition("name", ConditionOperator.Equal, parentOpportunity);
EntityCollection pricelistItems = Service.RetrieveMultiple(query);
var a = pricelistItems.Entities[0];
string priceList1 = a.Attributes["pricelevelid"].ToString();
QueryExpression query2 = new QueryExpression("pricelevel");
ColumnSet columns2 = new ColumnSet("new_basicdealerdiscount");
query2.ColumnSet = columns2;
query2.Criteria.AddCondition("pricelevelid", ConditionOperator.Equal, priceList1);
EntityCollection discountItem = Service.RetrieveMultiple(query2);
But when I run this code it is giving me error:
An exception System.FormatException was thrown while trying to convert input value 'Microsoft.Xrm.Sdk.EntityReference' to attribute 'pricelevel.pricelevelid'. Expected type of attribute value: System.Guid...........
Please help.
Thanks in advance !!