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

One thought on “Retrieve Product Properties using JavaScript in CRM 2015

  1. Unknown July 5, 2018 / 8:43 am

    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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s