I have this global action with one entity-reference input parameter and one output parameter(string).
function CallGlobalCustomAction(executionContext) {
if(!executionContext) {
console.log("no execution context found");
return;
}
var formContext = executionContext.getFormContext();
if(!formContext) {
console.log("no form context found");
return;
}
//get the current organization name
var serverURL = formContext.context.getClientUrl();
//query to send the request to the global Action
var actionName = "osm_OSMActionTaskSendEmail251267fffe73ea11a811000d3a86b423"; // Global Action Unique Name
//set the current loggedin userid in to _inputParameter of the
var InputParameterValue = formContext.context.getUserId();
//Pass the input parameters of action
var data = {
"entityType" : "systemuser",
"id": InputParameterValue
};
//Create the HttpRequestObject to send WEB API Request
var req = new XMLHttpRequest();
//Post the WEB API Request
req.open("POST", serverURL + "/api/data/v9.1/" + actionName, true);
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 /* complete */)
{
req.onreadystatechange = null;
if (this.status == 200 || this.status == 204)
{
alert("Action Executed Successfully...");
//You can get the output parameter of the action with name as given below
result = JSON.parse(this.response);
alert(result.Status);
}
else
{
var error = JSON.parse(this.response).error;
alert("Error in Action: "+error.message);
}
}
};
//Execute request passing the input parameter of the action
req.send(window.JSON.stringify(data));
}