web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

update a record using POST Odata calls

(0) ShareShare
ReportReport
Posted on by 95

I am working on a scenario where i want to update a record some other entity using POST method OData calls javascript.

Below is my code :

function SetAverageSalitaRating() {
try {
debugger;
if (Xrm.Page.getAttribute("sal_interpreter").getValue()) {

var interpreterId = Xrm.Page.getAttribute("sal_interpreter").getValue()[0].id;

interpreterId = interpreterId.substring(1, interpreterId.length - 1);
var ServerUrl = Xrm.Page.context.getClientUrl();

var Entity_name1 = "/api/data/v8.1/sal_interpreterses(";
var Entity_name2 = ")";
odataselect1 = ServerUrl + Entity_name1 + interpreterId + Entity_name2;
var objAccount = new Object();
objAccount.sal_salitarating = 1;
objAccount.sal_address1visit = "vivek";
var jsonEntity = window.JSON.stringify(objAccount);
$.ajax({

type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataselect1,
data: jsonEntity,
async: false,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
alert("yeah");
},
success: function (data, textStatus, XmlHttpRequest) {
alert("Updated successfully");
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
}
});

}
}
catch (e) {
throw new Error(e.message);
}
}

Here my control is going inside 'success' method . Please help

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ganeshm Profile Picture
    on at


    function set() {
    var accountId = Xrm.Page.data.entity.getId().slice(1,-1);

    var obj = new Object();
    // set the name of Account
    // objAccount={name:Account test update};
    obj.name="ttt";
    var jsonEntity = window.JSON.stringify(obj);

    var serverUrl = Xrm.Page.context.getClientUrl();
    var ODATA_ENDPOINT = "/api/data/v8.1/accounts";
    var ODataPath = serverUrl + ODATA_ENDPOINT;
    $.ajax({
    type: "PATCH",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    async: false,
    url: ODataPath + "(" + accountId + ")",
    data: jsonEntity,
    beforeSend: function (XMLHttpRequest) {
    XMLHttpRequest.setRequestHeader("Accept", "application/json");
    XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
    },
    error: function (xmlHttpRequest, textStatus, errorThrown) {
    alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
    }});}

    try using Patch operation for update not post

  • Suggested answer
    ganeshm Profile Picture
    on at

    If u have make update using Post then, try change ur odata_endpoint  to https://[orgname]/XRMServices/2011/OrganizationData.svc/(entity_name),

    check web api call type for crud operation.refer:

    msdn.microsoft.com/.../mt628816.aspx

  • Suggested answer
    Bobins Bansala Profile Picture
    95 on at

    thxns a lot

    type: "PATCH" solved my problem

  • Bobins Bansala Profile Picture
    95 on at

    also can you please explain why we use PATCH and not POST

  • Verified answer
    ganeshm Profile Picture
    on at

    well 'post' is only used for create operations using web api.This link give a brief explanation on http methods on rest  ,

    www.restapitutorial.com/.../httpmethods.html.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans