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 :
Service | Customer Service, Contact Center, Fie...
Unanswered

Trying to update the status of a case to "Resolved" using Javascript web resources

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to update the status of a case to "Resolved" using JavaScript web resources but the case status is not getting updated. If I am using the same code in REST builder and it is changing to Resolved. Can someone suggest the changes or point out the error in my code ???

<script>
function getdata()
{

var CId = localStorage.getItem("record_id");
var CIDFormatted = CId.toString().slice(1, -1);
alert(CId);

var entity = {};
entity.statuscode.Value=5;


var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/incidents(" + CIDFormatted + ")", false);
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) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}

</script>

Thanks,

Abhilash

I have the same question (0)
  • Minghao Yang Profile Picture
    75 on at

    Hi Abhilash,

    Have you tried debugging through the JS function? If not I would suggest you to do that, and please pay attention to the "CIDFormatted " variable when you pass it and see if it's the correct GUID of the case(incident) which you want to update.

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    If you are using js function in the case form, you could refer to the following code using "xrm.webapi.updaterecord" instead.

    function setCaseResolved(){
        var CId = localStorage.getItem("record_id");
        var data={
            "statuscode":5

        };
        Xrm.WebApi.updateRecord("incident",CId,data).then(
            function success(){
                //todo...
            },
            function(error){
                //todo...
            }
        );

    }

    And pay attention  to the "CId" if its format is correct like "5531d753-9457........".

    If you want to update the case to resolved in html web resources, you could try to change your code like this.

    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/incidents('" + CIDFormatted + "')", false);

    Hope it helps.

    Best Regards,

    Leo

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 55 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Soundari Profile Picture

Soundari 15

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans