Quantcast
Channel: Sam's Activities
Viewing all articles
Browse latest Browse all 3363

Execute Action with “EntityCollection” Parameter using Web API in Dynamics 365

$
0
0

Introduction

Recently, we had a requirement where we wanted to Execute Custom Action in Dynamics CRM by passing “EntityCollection” type parameter using Web API. We have discussed how to execute the action using Web API in one of our earlier blog. However, in this blog we just explained executing action with string parameter.

Here we are going to focus on executing action with “EntityCollection” parameter using Web API.

You can see below that we have created a Custom Action:

Dynamics CRM Web API

Below code snippet will help you to Execute Action using Web API:

function CallCustomActionWithEntityCollectionParameter() {
    try {

        var reqName = "new_Approve";
        var clientUrl = Xrm.Page.context.getClientUrl();
        var parameters = {"Accounts"://EntityCollection parameter
             [
                  {"@odata.type": "Microsoft.Dynamics.CRM.account",//entity type"accountid": "C4CA0B66-59B9-E611-8106-C4346BDC0E01",//Record's guid"name": "Test",//name field of the account entity"accountnumber": "123"//accountnumber field of the account entity
                  },
                  {"@odata.type": "Microsoft.Dynamics.CRM.account","accountid": "CD67D78E-16BB-E611-8109-C4346BDC3C21","name": "Test2","accountnumber": "1234"
                  }
             ]
        };

        //Create request
        var req = new XMLHttpRequest();
        req.open("POST", clientUrl + "/api/data/v8.2/" + reqName, 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) {
                    //success callback
                    console.log("Success");
                } else {
                    //error callback
                    console.log("Error");
                }
            }
        };
        req.send(JSON.stringify(parameters));

    } catch (e) {
        alert(e.message);
    }
}

Conclusion:

This blog will help you to execute action by passing “EntityCollection” parameter using Web API in Dynamics 365.

Now export Dynamics 365 reports to multiple formats in mere one click using Click2Export!


Viewing all articles
Browse latest Browse all 3363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>