I'm having trouble calling my global custom action using JavaScript in Dynamics CRM.
In CRM I created this global action that takes an in parameter and returns an out parameter. I've confirmed that the action is activated and works. The problem arises when I try to call it using JavaScript.
My JavaScript code is as follows:
callCustomAction: function (actionName, actionParameters) {
var result = null;
var req = new XMLHttpRequest();
req.open("POST", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + actionName), false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
result = JSON.parse(this.response);
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(window.JSON.stringify(actionParameters));
return result;
}
Now, to me this looks correct but I got an issue with the URL which at the moment leads to nowhere. Everywhere I look the URL for a global action is simply the organization URL followed by "/api/data/v8.2/" and the name of my action but for me it's not working and I can't figure out why.
Resolved The issue was using a mix of EntityReferences and strings as out parameters which made my action not show up under metadata