Fixed – Executing Action with Complex Output Parameters through Web API in Dynamics 365 v9.0

By | January 4, 2018


While working on Dynamics 365, we get a chance to work on lot many things.

At times you work on C# or JavaScript or SSRS or SSIS. Having knowledge of so many languages, frameworks, or technologies could be taxing.

Sometimes we face errors while developing something and don’t have control over how it could be fixed.

One such thing was executing Action using Web API.

Prior to v9.0 update, if we tried executing Actions, having combination of complex and simple output parameters would result in errors like, Resource not found for the segment ‘ActionName’ or Request message has unresolved parameters.

In order to understand what complex and simple parameters are, please check a very well explained blog written by Andrew Butenko.

Now, in v9.0 we don’t have to worry about the combinations of the output parameters.

Irrespective of the combination of the output parameters, we are able to execute the Action.

Code Snippet:

function executeAction(accountId, actionName, clientUrl) {
    var functionName = "executeAction >>";
    var query = "";
    try {

        //Define the query to execute the action
        query = "accounts(" + accountId + ")/Microsoft.Dynamics.CRM."+actionName;

        var req = new XMLHttpRequest();"POST", clientUrl + "/api/data/v9.0/" + query, 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) {
                    //success callback
                    var result = JSON.parse(this.response);

                } else {
                    //error callback
                    var error = JSON.parse(this.response).error;

    } catch (e) {
        throwError(functionName, e);


We can combine simple and complex output parameters and still execute the Action through Web API in Dynamics 365 v9.0

Export Dynamics CRM Reports

3 thoughts on “Fixed – Executing Action with Complex Output Parameters through Web API in Dynamics 365 v9.0

  1. Hayer

    Hi, Thanks for sharing. But I have got an error at line below:

    It is saying that “data” is not defined. Then I initialised the data like “var data = {};”

    but now I go following error at same link:
    Failed to load resource: the server responded with a status of 404 ()

    My custom action does not have any input parameter.


    1. inogic Post author


      From your comment, it seems that you are not having any input parameters in your action. So you can simply change “req.send(JSON.stringify(data));” to “req.send();”

      Hope this helps.


    2. Sohail

      function accountCustomAction() {
      var accountId =;
      accountId = accountId.replace(“{“, “”).replace(“}”, “”);
      var parameters = {};
      parameters.PrimaryID = accountId;
      var req = new XMLHttpRequest();“POST”, Xrm.Page.context.getClientUrl() + “/api/data/v8.2/accounts(” + accountId + “)/Microsoft.Dynamics.CRM.cr1b8_CustomActionPluginAccountEntity”, true);
      req.setRequestHeader(“OData-MaxVersion”, “4.0”);
      req.setRequestHeader(“OData-Version”, “4.0”);
      req.setRequestHeader(“Accept”, “application/json”);
      req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
      req.onreadystatechange = function () {
      if (this.readyState === 4) {
      req.onreadystatechange = null;
      if (this.status === 200) {
      var results = JSON.parse(this.response);
      if (results !== null) {
      if (results.AccountID !== null || results.AccountID !== “undefined”) {
      alert(“Success: ” + results.AccountID);
      else {
      alert(“Action called successfully”);


Leave a Reply

Your email address will not be published. Required fields are marked *