Thursday, 12 November 2015

Retrieve Product Properties using JavaScript in CRM 2015

Hi,

Today we got a requirement to show Product Properties related to Opportunity Product in a HTML Webresource.

Here is the JavaScript code to read Product Properties.


  function getProperties() {
            var jsonResult = null;
            var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
            var retrieveRecordsReq = new XMLHttpRequest();
            var oDataPath = "";
            var entityName = "DynamicPropertyInstance";
            var entityNameField = "*";
            oDataPath = Xrm.Page.context.getClientUrl() + ODATA_ENDPOINT + "/" + entityName + "Set?$select=*&$filter=RegardingObjectId/Id eq guid'" + vOpportunityProductId + "'";
            retrieveRecordsReq.open('GET', oDataPath, false);
            retrieveRecordsReq.setRequestHeader("Accept", "application/json");
            retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8")
            retrieveRecordsReq.send(null);
            var retrievedData = JSON.parse(retrieveRecordsReq.responseText).d;
            if (retrievedData != null && retrievedData != undefined && retrievedData.results != null) {
                jsonResult = retrievedData.results;
            }
             return jsonResult;
        }
Hope this helps.

--

Happy CRM'ing
Gopinath

1 comment:

  1. this will only give you the values of the properties , the name field is null, it is in dynamicproperty entity, how to get both ? i tried retrieveproductproperties function but cannot get value

    ReplyDelete