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

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Trying to update the status of a case to "Resolved" using Javascript web resources

    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

  • Minghao Yang Profile Picture
    75 on at
    RE: Trying to update the status of a case to "Resolved" using Javascript web resources

    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.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#2
Ramesh Kumar Profile Picture

Ramesh Kumar 42

#3
David Shaw_UK Profile Picture

David Shaw_UK 27

Featured topics

Product updates

Dynamics 365 release plans