Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

WEB API CloseIncident Action and IsValidStateTransition Function

Posted on by

Why does the WEB API CloseIncident Action cancel the activities and does not check if the case has been saved? I was hoping to get those checks as well.

However ... since I like this action ... I'm still trying to find a way to use it, but first of all I need a way to check for open activities and if mandatory fields are filled in.

I tried to use the IsValidStateTransition Function since, as far as I understood, for the corresponding organization service IsValidStateTransitionRequest an exception is thrown if an incident (case) has open activities but I can't bring it to work!!!

Here what I've tried:

var parameters = {};
parameters.Entity = {'@odata.id':'incidents(47E71C9D-7902-E711-80FA-5065F38A1B01)'};
parameters.NewState = "Resolved";
parameters.NewStatus = 922210005;

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/IsValidStateTransition()", 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 === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(parameters));

but I get "Internal Server Error"

then I tried following:

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/IsValidStateTransition(Entity=@ent,NewState='Resolved',NewStatus=922210005)?@ent={'@odata.id':'incidents(47E71C9D-7902-E711-80FA-5065F38A1B01)'}", 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 === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify());

but it still doesn't want to work

Any help is highly appreciated!

*This post is locked for comments

  • Suggested answer
    RE: WEB API CloseIncident Action and IsValidStateTransition Function

    In the meantime I solved the open Activities check with a query:

    function NoOpenActivitiesCheck(selectedItem) {
    var ret = true;
    var counterOpenActivities = 0;
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents("+selectedItem+")?$select=incidentid&$expand=Incident_ActivityPointers($select=statecode)", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.setRequestHeader("CACHE-CONTROL", "NO-CACHE");
    req.onreadystatechange = function() {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var result = JSON.parse(this.response);
    var incidentid = result["incidentid"];
    for (var a = 0; a < result.Incident_ActivityPointers.length; a++) {
    var incident_ActivityPointers_statecode = result.Incident_ActivityPointers[a]["statecode"];
    var incident_ActivityPointers_statecode_formatted = result.Incident_ActivityPointers[a]["statecode@OData.Community.Display.V1.FormattedValue"];
    if(incident_ActivityPointers_statecode_formatted.toString()=="Open") counterOpenActivities++;
    }
    if(counterOpenActivities>0) {
    ret = false;
    Xrm.Utility.alertDialog("There are open activities associated with this case. The case cannot be resolved. Please close the open activities before resolving the case.");
    }
    return ret;
    } else {
    Xrm.Utility.alertDialog(this.statusText);
    return ret;
    }
    }
    };
    req.send();
    return ret;
    }

    But I'm still interested in knowing if somebody has ever used the IsValidStateTransition Function.

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