Calling bound actions (entity actions) using Xrm.WebApi.execute in Dynamics V9
This is a follow up to my previous blog where I showed you how can you call a global action with all parameter types using the newly introduced Xrm.WebApi.execute method.
Now coming to bound actions i.e actions which are bound to entities, I was getting multiple queries on how to do it after my first blog post. Readers were telling that they are unable to call the action after repeated trials. I was perplexed. So I thought, why not give a try.
So I created a very simple action with the below details:
Name: new_TestProcess
Bound to entity: Account
Input Parameter – EntityReference of type custom entity named new_TestEntity
So harmless isn’t it. Even I was thinking the same till it took me more than couple of hours to figure out on how to call this action using Xrm.WebApi.execute.
So let’s dive into the code. The first thing we need to understand is how to pass the parameter for the bound entity. In other words this action will always be called on account record. And how do you pass the account record reference?
Well, the first thing that came to my mind is the input parameter must be named as “Target”. After all that is the convention created by Microsoft right? Well in-fact it’s bit different. It’s not “Target”. Then how do I find out the parameter name.
- Settings –> Customizations –> Developer resources
- Dowload Web Api Metadata
- Once downloaded, open up the metadata in Visual studio or any other XML editor of your choice. Search for your action. In this case – “new_TestProcess”.
- Below is my metadata for my action. See the highlighted line. From that it is clear that the bound entity parameter type is “entity” and not “Target”
Ok, past the first hurdle. Now comes my nightmare.
Highlighting Microsoft Documentation for Xrm.WebApi.execute below
Well, a very detailed documentation I would say. Everything is pretty much explained. But let’s shift our focus to to the highlighted line which says that for entity actions, we need to set the boundParameter to entity logical name or entity set name. Well, that’s when my ordeal started.
Started with all possible combinations like “mscrm.account”/ “Microsoft.Dynamics.CRM.Account”/”account”/”accounts” and a host of illogical others which are all ridiculous. ![]()
Finally just before giving up , I started debugging and went around whichever files the browser takes me in while debugging. And finally eureka moment when I realized that you need to set the value of boundParameter to the word “entity”. Could anyone imagine that from the statement in the documentation.
And finally piece of code below for you
var target = { entityType: "account", id: "78FA0233-7D86-E811-A94D-000D3A3AB6B4" };
var reqObject = {};
reqObject.entity = target;
reqObject.ArgEntRef = { "@odata.type": "Microsoft.Dynamics.CRM.new_testentity", "@new_testentity.id": "C182D39E-6B8B-E811-A94D-000D3A3AB6B4" }
reqObject.getMetadata = function () {
return {
boundParameter: "entity",
operationType: 0,
operationName: "new_TestProcess",
parameterTypes: {
"entity": {
typeName: "mscrm.account",
structuralProperty: 5
}, "ArgEntRef":{typeName: "mscrm.new_testentity",
structuralProperty: 5}
}
}
};
Xrm.WebApi.execute(reqObject).then(
function (data) {
var e = data;
debugger;
},
function (error) {
debugger;
var errMsg = error.message;
}
);
Hope this helps!
-Debajit Dutta
(Dynamics MVP)
For consultation/ training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
This was originally posted here.

Like
Report
*This post is locked for comments