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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

WEB API CloseIncident Action and IsValidStateTransition Function

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    sdibartolomeo Profile Picture
    on at

    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans