Thursday, 30 July 2015

RetrieveProductPropertiesRequest message in CRM 2015


In CRM 2015, we have new feature of having properties to the Products. Sometimes, we get a requirement to retrieve them using SDK.

We can retrieve them in two ways
1) Using the new message - RetrieveProductPropertiesRequest
2) Using our ever green Fetch XML

RetrieveProductPropertiesRequest expects a parent object(entityreference) for retrieving the properites of the product. Parent Object can be Quote Product, Opportunity Product, Invoice Product or Order Product.

RetrieveProductPropertiesRequest objRetrieveProductPropertyReq = new RetrieveProductPropertiesRequest();
objRetrieveProductPropertyReq.ParentObject = new EntityReference("quotedetail", new Guid(""));
RetrieveProductPropertiesResponse objRetrieveProductPropertiesResponse = (RetrieveProductPropertiesResponse)iService.Execute(objRetrieveProductPropertyReq);
EntityCollection entProductProperties = objRetrieveProductPropertiesResponse.EntityCollection;

If you are using Fetch XML, just the guid of Quote Product, Opportunity Product, Invoice Product or Order Product against regardingobject.

string strFetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
   <entity name='dynamicpropertyinstance'>
   <filter type='and'>
   <condition attribute='regardingobjectid' operator='eq' value='{}' />
EntityCollection entColDynamicProperties = iService.RetrieveMultiple(new FetchExpression(strFetchXML));

Hope this helps.

Happy CRM'ing

No comments:

Post a Comment