简体   繁体   中英

CRM 2011 Update Using the REST Endpoint with JavaScript fails

In MS Dynamics CRM 2011 (which is new to me, I haven't worked with it prior to a few weeks ago), I'm trying to update a custom entity field value from the onsave event of a form. Here's the script saved in the WebResource attached to the form and the onsave event there (_orgDataPath is retrieved from the page context and works eg for a Retrieve request on the same form, so it does not appear to be the source of the issue here):

function updateRecord(id, type) {  
        var object = { new_CurrentIndex: 12345 };
        var req = new XMLHttpRequest();
        req.open("POST", encodeURI(this._orgDataPath() + type + "Set(guid'" + id + "')"), false);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("X-HTTP-Method", "MERGE");

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

        req.send(jsonEntity);
}

When I run this in the form's onsave event, the new_CurrentIndex value of the custom entity is not updated.

So my questions are: 1) Is the code above correct for a synchronous REST update using javascript? 2) If the code for the basic REST update above is correct, are there CRM configuration settings that would prevent the update from succeeding?

f12将打开开发人员工具-使用调试并逐步调用其功能,以查看出现问题的地方

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM