Reputation: 1
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
Upvotes: 0
Views: 3222
Reputation: 21
Global actions which have an output parameter associated cant be called using the Web API. This is not the case for actions having no output parameter.
This is because sometimes the status code is 200 and sometimes different. We noticed this bug and observed it to happen only with actions having output parameter. Also we noticed this happening on certain times and not frequently as in at times you will get output but sometimes not.
As a workaround, you need to use the conventional SOAP query and execute the workflow and then parse the response.
Hope MS solves this soon
Upvotes: 0