You can call the Action in JavaScript in Dynamics 365
function dupcontact(executionContext) {
//console.log("this is a test");
//alert("a test");
//get the current organization name
var serverURL = Xrm.Page.context.getClientUrl();
//query to send the request to the global Action
var query="packt_CreateStudent";
//Pass the input parameters of action
var data = {
"FirstName": "Rui1",
"LastName":"Liu",
"EmailAddress": "Liu.Rui1@qq.com"
}
//Create the HttpRequestObject to send WEB API Request
var req = new XMLHttpRequest();
//Post the WEB API Request
req.open("POST",encodeURI(serverURL + "/api/data/v9.1/packt_CreateStudent"), 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;
// 200 -- With output parameter
// 204 -- action without output parameter
if (this.status == 200) {
//You can get the output parameter of the action with name as given below
result = JSON.parse(this.response);
alert(result.CreatedStudent);
//success callback
} else {
var error = JSON.parse(this.response).error;
//error callback
alert(error.message);
}
}
};
//Execute request passing the input parameter of the action
req.send(window.JSON.stringify(data));
}