{Quick Tip} Pass a custom single/ collection of objects with Custom Properties as Output parameter from Actions in Dynamics 365

One of the great features that got introduced with Dynamics 2013 was Actions. With time more & more improvement came in with Actions and today Actions are one of the most powerful extending features in Dynamics.

And here I was designing actions for a client. Coming quickly to the requirement, the client had an action where they were determining complex business logic in the action with some input parameters and then based on the calculation, they need to pass back multiple values back to the invoker of the action.

There can be multiple ways to do this and one can be pass each of these values of Output Parameters. But that did not go well with the customer as around 15 properties needed to be returned from the action.

So the client developer came up with a DataModel class something similar to this.


internal class OutputClass


public string Property1{get;set;}




public decimal Property15{get;set;}



Nothing fancy. all the developer was doing was mapping the properties of this class and then the object back to the invoker of the action. But how to do it? Does Action allow custom object types to be passed as return parameters. Well,direct answer is No. But there are ways.

  • serialize the object into JSON and put the output JSON string through a string Output parameter – Didn’t go well with the customer. Has to abandon
  • serialize the object into XML and put the output XML string through a string Output parameter – Didn’t go well with the customer. Has to abandon again.


What I am left with then? We all know that it supports entity and entitycollection as output parameter types. But how do I use them to accomplish my goal here. The customer is not willing to create any Entity specifically for this.

Well a bit of trial and finally I achieved the below as workaround.

1. Passing a single Object back.

Well for this I used the entity parameter and just selected the Account Entity as Entity Type. You can use any Entity here. Does not matter.



In the plugin registered on the Action step, after calculating all the properties, I am setting the Output parameter like this.

var ent = new Entity("account");
ent["mytestproperty"] = "Test Name";
ent["mytestproperty2"] = 1;

ent["myentityreference"] = new EntityReference("contact", Guid.NewGuid());

context.OutputParameters["EntityParam"] = ent;

Observe carefully the code above. I am just creating an entity at runtime of type “account”. I don’t need to even specify the Guid. And then I can just put my custom property names for the entity and assign values of entity type – string/ int/ decimal/ entityreference etc.

None of these properties are present in the account entity. The trick is CRM framework does not validate the fields of the entity. So you can just return the entity object back with your own parameters. Cool trick. Isn’t it.

And below is the output received by the invoker of the action.



2. Passing Multiple Objects of Different type

For this, I used the entity collection as Output parameter



And below is the code to set the values.

var ent = new Entity("account");
           ent["mytestproperty"] = "Test Name";
           ent["mytestproperty2"] = 1;
           ent["myentityreference"] = new EntityReference("contact", Guid.Empty);

           var ent2 = new Entity("contact");
           ent2["mytestproperty"] = "Test Name";
           ent2["mytestproperty2"] = 1;
           ent2["myentityreference"] = new EntityReference("contact", Guid.Empty);


           context.OutputParameters["CollectionParam"] = collection;

First we have to understand that entitycollection is a collection of entities. It does not necessarily imply collection of entities of the same type. This is a common misconception I find among so many people in spite of working on CRM for quite sometime.

As you can see, both the entities are of different types and can have completely different properties. Cool isn’t it?

And Below is the result the invoker of the action receives.



Personally if you ask me, I would still prefer serializing the object into JSON or XML. However if your customer prefers Entity or EntityCollection, this workaround I hope helps you.


Debajit Dutta

(Dynamics MVP)

For corporate training/ consulting/ tools, please visit our website www.xrmforyou.com or write to us at info@xrmforyou.com

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s