We have covered how to call a custom action in JavaScript in
a previous blog.
But sometimes there are scenarios you need to create Global
Actions where you don't specify an entity in particularly. When you create such
a global action and if you need to call that action from your JavaScript code
how can you do it?
Let's say this is your Global Action. Please note the name
and the Unique Name. Unique name is the one you need to use in the code.
Then use the following code to call your action. Replace the "your action name" with the unique name of your action.
function CallAction()
{
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_TestGlobalAction", 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) {
alert("Action Called");
//Success
- No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Make sure your action is activated!
I tried calling Global Action through the Web Api following same procedure but i am getting error :- "No HTTP resource was found that matches the request URI".
ReplyDeleteKindly suggest some solution if anybody faced the same issue prior.
Sorry for the late reply; did you use the schema name of your action? including the prefix
ReplyDelete