Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Updating a record using ODATA end point?

Posted on by 377

Hi i'm trying to updating a existing record by passing guid variable from the web page using Odata endpoint. If i hard coded the value its working fine, but if i make it dynamic  by passing variable , its not updating a record. i thought its taking double quotes along with GUID, i'm not sure . Please help me if anybody knows the solution.

Thanks in advance.

function updateExistingXmlRecord(fetch, name,guid) {
var entity = {};
entity.new_fetchxml = fetch;
entity.new_name = name;
var newguid=guid.replace(/\"/g,'');

var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_*******(newguid)", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var results = JSON.parse(this.response);
alert(results);
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}

*This post is locked for comments

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Updating a record using ODATA end point?

    Hello,

    It may be it's taking some space, try to use  

    var newguid=guid.substring(1, 37);

    If this does not solve your problem I will suggest you to debug your code, and check in the watch windows if the GUID is coming correctly.

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Updating a record using ODATA end point?

    Logically it's not possible, if the hard coded value and parameter guid is same then I don't think error is coming only for GUID parameter.

  • ZeroHar Profile Picture
    ZeroHar 377 on at
    RE: Updating a record using ODATA end point?

    yeah i think so. but i am passing same guid value as hardcoded value .this time its working.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Updating a record using ODATA end point?

    Seems the error is coming from your data passing in a entity object. If the  GUID is coming without  {}  then you don't need to replace anything.

    I have one doubt when you hard coded the guid then everything is same in the entity object?

    If it's same may be  when the guid you are passing without hard coded is not found in the CRM so the problem with your guid value not format.

  • ZeroHar Profile Picture
    ZeroHar 377 on at
    RE: Updating a record using ODATA end point?

    when i did debug, im getting the value like this. intially i'm not getting any curly braces, but still its not updating

    4377.Capture.PNG

    even after i replaced the code with "var newguid = guid.replace("{", "").replace("}", "");"  same error is shown up

    Error:  message :entity is not defined

                stack : "ReferenceError:entity is not defined at eval"

  • Suggested answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Updating a record using ODATA end point?

    Debug/log the 'newguid' variable and check the value.

    As Goutham said, ensure that the curly braces are removed.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Updating a record using ODATA end point?

    Hi ,

    Seems you are correct , if you are saying that for hard code value its working then the problem is with your data . You are correct remove the "{ }"  from your GUID.

    Here is the code -

    var newguid = guid.replace("{", "").replace("}", "");

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans