Dynamics Version 9.0 introduced the Xrm.WebApi namespace which provides all the methods to interact with dynamics CRM server from client side script.
However recently I was working on a project to upgrade the SOAP calls from client and replace them with the new Xrm.WebApi methods. Create/ delete/ update were kind of easy and was easily ported to the new API’s.
However then came the Actions. The client had actions which had many input parameters and which were getting invoked from the client using SOAP calls. We had to port them to the Xrm.WebApi. But in Xrm.WebApi we did not had any function like executeAction. But the Xrm.WebApi.execute came to our rescue.
Let’s first examine Xrm.WebApi.execute method. Microsoft documentation shows it like this –
For the sake of brevity of this blog post, I am skipping the documentation of the parameters. For detailed information on the parameters, please refer the below Microsoft documentation link – https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/execute
So how to call an action with input parameters? For this post, I created an action named “new_TestAction”. The action is global. It has the following input parameters.
- Name – Type (string)
- Age – Type(string)
- InputEntityReference – Type (EntityReference)
- InputEntity – Type (Entity)
- InputEntityCollection – Type(EntityCollection)
For entityreference, entitycollection and entity, I have kept the Entity as Account Entity. All set and done. Now the next step is to call the action. below is the sample code to create the request object. All the important parameters has been highlighted and appropriate comments put.
TestAction1: function (input1, input2, inputEntityReference, inputAccount, inputAccountCollection) ,
operationType: 0, // 0 for action, 1 for function and 2 for CRUD
Next is the code to create this request object and pass the object to the action.
ExecuteAction: function () ;
var accountEntity = ;
var accountEntityCollection =[
var requestObject = new TestAction1(“Name”, “Age”, accountReference, accountEntity, accountEntityCollection);
Xrm.WebApi.execute(requestObject).then(function (result) ,
function (error) );
Simple isn’t it. I haven’t covered the other primitive types like – Decimal/ Int. They are pretty simple like for int, it is Edm.Int32.
Hope this helps!