Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

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

$
0
0

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() {
    debugger;
    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]);
        alert(sp_Amt);
        amtp = String(sp_Amt);
        alert(amtp);
AddRate.new_land_amount = amtp.toString();


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

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

        var id = ids[t].replace("{", "").replace("}", "");
        t++;
        //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
        $.ajax({
            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) { }
        });
    }
    document.getElementById("sp").control.refresh();
}

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



Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>