Calling bound actions (entity actions) using Xrm.WebApi.execute in Dynamics V9

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.

https://debajmecrm.com/2018/02/02/dynamics-version-9-0-execute-custom-action-with-all-parameter-types-in-dynamics-crm-version-9-0/

 

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

image

 

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

image

  • 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”

image

 

Ok, past the first hurdle. Now comes my nightmare.

Highlighting Microsoft Documentation for Xrm.WebApi.execute below

image

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. Smile

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 = ;

    var reqObject = ;
    reqObject.entity = target;
    reqObject.ArgEntRef =

    reqObject.getMetadata = function () , "ArgEntRef":
            }
        }
    };

    Xrm.WebApi.execute(reqObject).then(
        function (data) ,
        function (error)
        );

 

Hope this helps!

-Debajit Dutta

(Dynamics MVP)

For consultation/ training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Advertisements

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side.

Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com

Author of multiple tools on codeplex including the ‘Role Based Views’ and ‘CRM-Sharepoint Metadata manager & Attachment Extractor’ which are available for commercial use under XrmForYou.com

For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Published at Fri, 20 Jul 2018 09:08:47 +0000

Leave a Reply

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