I am trying to call a custom action from JavaScript in Dynamics 365 Online v9, but I am getting an error "Resource not found for the segment new_sendcrmcontactdatatoaba" where new_sendcrmcontactdatatoaba is the name of the action. The action has four string input parameters and one string output parameter.
Here is my JavaScript to call the action:
...
var parameters = {
"Environment": environment,
"StrURL": strURL,
"RecordId": contactID,
"RecordType": "contact"
}
var results = callAction('new_SendCRMContactDatatoABA', 'contacts', parameters);
...
function callAction(actionName, entityName, actionParams) {
var result = null;
var oDataEndPoint = encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v9.0/Microsoft.Dynamics.CRM." + actionName);
var request = new XMLHttpRequest();
request.open("POST", oDataEndPoint, false);
request.setRequestHeader("OData-MaxVersion", "4.0");
request.setRequestHeader("OData-Version", "4.0");
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
request.onreadystatechange = function () {
if (request.readyState === 4) {
request.onreadystatechange = null;
if (request.status === 200) {
result = JSON.parse(this.response);
} else {
var error = JSON.parse(this.response).error;
alert("Error calling action: " + actionName + error.message);
}
}
};
if (actionParams != null)
request.send(JSON.stringify(actionParams));
else
request.send();
return result;
}
The action is defined as a global action with the following parameters:
Environment, String, Required, Input
StrURL, String, Required, Input
RecordId, String, Required, Input
RecordType, String, Required, Input
Message, String, Required, Output
Does anyone have any idea how to get this action to work?
*This post is locked for comments
Thank you Jason. That fixed it.
Try removing "Microsoft.Dynamics.CRM." from the url. That usually appear only when the action is bound to an entity.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156