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

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested answer

Dynamics 365 CE - How to cancel a case using WebApi in Javascript

(0) ShareShare
ReportReport
Posted on by

How to cancel a case using WebApi. I am currently doing it using the 2011 endpoint SOAP call, but I want to upgrade it to a newer version of WebApi. I am able to 'resolve' a case, but not able to 'cancel' it from JavaScript.

My current 2011 soap call code is :

// create the SetState request
        var request = "<s:Envelope xmlns:s=\"";">schemas.xmlsoap.org/.../\">";
        request += "<s:Body>";
        request += "<Execute xmlns=\"">schemas.microsoft.com/.../Services\" xmlns:i=\"";">www.w3.org/.../XMLSchema-instance\">";
        request += "<request i:type=\"b:SetStateRequest\" xmlns:a=\"">schemas.microsoft.com/.../Contracts\" xmlns:b=\"";">schemas.microsoft.com/.../Contracts\">";
        request += "<a:Parameters xmlns:c=\"";">schemas.datacontract.org/.../System.Collections.Generic\">";
        request += "<a:KeyValuePairOfstringanyType>";
        request += "<c:key>EntityMoniker</c:key>";
        request += "<c:value i:type=\"a:EntityReference\">";
        request += "<a:Id>" + formContext.data.entity.getId() + "</a:Id>";
        request += "<a:LogicalName>incident</a:LogicalName>";
        request += "<a:Name i:nil=\"true\" />";
        request += "</c:value>";
        request += "</a:KeyValuePairOfstringanyType>";
        request += "<a:KeyValuePairOfstringanyType>";
        request += "<c:key>State</c:key>";
        request += "<c:value i:type=\"a:OptionSetValue\">";
        request += "<a:Value>" + selectedStatus + "</a:Value>";
        request += "</c:value>";
        request += "</a:KeyValuePairOfstringanyType>";
        request += "<a:KeyValuePairOfstringanyType>";
        request += "<c:key>Status</c:key>";
        request += "<c:value i:type=\"a:OptionSetValue\">";
        request += "<a:Value>" + selectedStatusReason + "</a:Value>";
        request += "</c:value>";
        request += "</a:KeyValuePairOfstringanyType>";
        request += "</a:Parameters>";
        request += "<a:RequestId i:nil=\"true\" />";
        request += "<a:RequestName>SetState</a:RequestName>";
        request += "</request>";
        request += "</Execute>";
        request += "</s:Body>";
        request += "</s:Envelope>";

        //send set state request
        $.ajax({
            type: "POST",
            async: false,
            contentType: "text/xml; charset=utf-8",
            datatype: "xml",
            url: Xrm.Utility.getGlobalContext().getClientUrl() + "/XRMServices/2011/Organization.svc/web",
            data: request,
            beforeSend: function (xmlHttpRequest) {
                xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                xmlHttpRequest.setRequestHeader("SOAPAction", "">schemas.microsoft.com/.../Execute");
            },
            success: function () {
                Alert.hide();
                formContext.ui.close();
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                Alert.hide();
                Xrm.Navigation.openErrorDialog({ errorCode: "Error in Cancel Ticket request", details: errorThrown }).then(
                    function () {},
                    function (error) {
                        console.log(error);
                    });
                console.log(errorThrown);
            }
        });
I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Dynamics 365 CE - How to cancel a case using WebApi in Javascript

    Hello,

    Nowadays following should work:

    Xrm.WebApi.updateRecord("incident", formContext.data.entity.getId(), {statecode: selectedStatus, statuscode: selectedStatusReason}).then(function() {}, function(e){console.log(e)});

  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Dynamics 365 CE - How to cancel a case using WebApi in Javascript

    Like I answered in SO, stackoverflow.com/.../7920473 this is working.

    var entity = {};

    entity.statecode = 2;  //Cancelled

    entity.statuscode = 6; //Cancelled

    Xrm.WebApi.online.updateRecord("incident", "1041db2d-196e-ea11-a811-000d3a5a1bf8", entity).then(

       function success(result) {

           //do something when request succeed

       },

       function(error) {

           //do something when request failed

       }

    );

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 49 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 46

#3
CU23101130-0 Profile Picture

CU23101130-0 17

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans