Monday, 12 October 2015

Error processing request stream. The request should be a valid top-level resource object CRM and oData

Hi,

Today I got the below error when I was trying to update Product Properties using Java Script.

Error processing request stream. The request should be a valid top-level resource object

The code is as follows.

function updateProductProperties() {
   var vUpdateProperty = {};
   vUpdateProperty.ValueString = "testing";
   vUpdateProperty.DynamicPropertyId = "guid";
   vUpdateProperty.RegardingObjectId = "guid"
   var vdynamicProductPropertyId = "<DynamicPropertyInstanceGUID>";
   SDK.REST.updateRecord(vdynamicProductPropertyId, vUpdateProperty, "DynamicPropertyInstance", function () { alert("The dynamic property instance record changes were saved"); }, function (error) { alert(error.message); });
}

After some search I figured out the error was because of type mismatch. When you get this type of error check the fields are mapped to correct data type references. In my case, I need to use Entity Reference Object where I used normal string.

Here is the correct code.

function updateProductProperties() {
    var vUpdateProperty = {};
    vUpdateProperty.ValueString = "testing";
    vUpdateProperty.DynamicPropertyId = { Id: "", LogicalName: "dynamicproperty" };
    vUpdateProperty.RegardingObjectId = { Id: "", LogicalName: "opportunityproduct" };
    var vdynamicProductPropertyId = "<DynamicPropertyInstanceGUID>";
    SDK.REST.updateRecord(vdynamicProductPropertyId, vUpdateProperty, "DynamicPropertyInstance", function () { alert("The dynamic property instance record changes were saved"); }, function (error) { alert(error.message); });
}

Hope this helps.

--
Happy CRM'ing
Gopinath

No comments:

Post a comment