Updating record through subgrid from one entity to another in crm 2011 rollup 13 RRS feed

  • Question

  • Hi All,

    We have a scenario where in we need to update the Subgrid based on a value changed in the calling entity.

    Lets say there are two custom entities:

    Custom Entity A

    Custom Entity B

    Note: There is no relationship existing between them, but I have displayed Entity B in Entity A as a Subgrid for a custom requirement.

    The cell value retrieved is from Entity B and updating another field in Entity B with that value.

    Code is as below:

    function AddRateCal() {
        var gridControl = document.getElementById("sp").control;
        var ids = gridControl.get_allRecordIds(); // Get the selected Ids of Sub-Grid
        var cnt = 0;
        var t = 0;
        var frate = 0;
        var spSum = 0;
        var amtp;
        for (var intRowNumber = 0; intRowNumber < gridControl.get_allRecordIds().length; intRowNumber++) {

            cnt = intRowNumber;
            var count = 0;
            var AddRate = new Object(); // object to be sent to CRM
            var sp_Amt = gridControl.getCellValue('new_percentage', gridControl.get_allRecordIds()[cnt]);
            amtp = String(sp_Amt);
    AddRate.new_land_amount = amtp.toString();

            var jsonEntity = window.JSON.stringify(AddRate);

            var ODataPath = "http://xxxxxx:5555/Org_CRM/XRMServices/2011/OrganizationData.svc/new_EntityB";

            var id = ids[t].replace("{", "").replace("}", "");
            //var id ="257b5FDC5392-263D-E211-B9E5-005056C00008";
            //AJAX Call using JQuery syntax. Please note the type--POST. To post something to CRM
            //To update a record you must pass GUID which is the identifier of the record.
            //For retrieval type would be GET
                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                data: jsonEntity,
                url: ODataPath + "(guid'" + id + "')",
                //url: ODataPath + type + "Set" + "(guid'" + id + "')",
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                    XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
                success: function (data, textStatus, XmlHttpRequest) {
                    // Refresh the Sub-Grid to reflect the changes.

                error: function (XMLHttpRequest, textStatus, errorThrown) { }

    Issue is that there is no error thrown, but the Entity B is not updated, when calling this JScript in the onchange event of Entity A. Is there something that I am missing here?

    Any inputs are greatly appreciated.

    Regards Sushant Sarkar Microsoft CRM Dynamics Engineer

    Tuesday, August 13, 2013 1:06 PM