Using Actions in Microsoft Dynamics CRM 2015

There was one question today in Microsoft Dynamics CRM Community Forum, where user was looking for the information about what is the use of Entity input parameter in Actions, so thought of writing a post, so that it can help others.

About Actions: Microsoft Dynamics CRM actions allows us to define our own custom events/messages, similar to existing standard events like Create,update,delete. Actions are designed using CRM process editor or using SDK and we can define parameters both (input and output) for these actions just like we have parameters for standard messages, for example if you want to use Create message, it takes Entity object as parameter and returns record GUID as output. Once activated we can also register plugin on the same.

You can get more details about action here:

Action Example: We are going to demonstrate how we can create and call actions. Actions provide us option to define different type of input and output parameters, but here we are going to demonstrate use of Entity and EntityReference Parameter. So let’s take an example that we want to create Contact from Account, very simple example for the demo. While creating contact we want to use information like name, email, telephone from account entity. Now to pass this information we have two option either we can pass all these fields from account to contact one by one or we can simply pass account entity object so that required field can be collected from there. So let’s create a action where we will use two input type of parameter, Entity and EntityReference, from entity we will use above fields and using entityreference we will get it of the sales person (we have created a custom lookup field on contact entity), using following steps to design action:

  • Navigate to Settings->Process->New.
  • Use following details and click on OK :
    1. Process name: ActionDemo
    2. Category: Action
    3. Entity: None(global)
    4. Type: New blank process
  • Add a Input parameter of Entity type for ParentAccount record like below:


  • Add another input parameter of type EntityReference to get Salesperson


Now let’s say we want to use these parameters to create our contact record, so follow below steps to create contact record using these parameters:

  • Click on Add Step and select Create Record step under drop down


  • Select Contact under Create drop down like below and click on Set Properties.
  • Now we will be using our Entity object input parameter to fetching different property and will be setting in contact record
  • Select the field that you want to set, for example we want to set Account Name, so click on Account Name field and click on OK after setting following options from Form Assistant like below:


  • Similar we can select other fields like Email, Mobile, Firstname, Last name from account entity object like belowcotnact
  • Now select the Sales person field and select out second parameter from Form assistant like below (Note: We have created a custom lookup for Sales Person field in Contact entity) and click on Save and Close

salespersonNow we need to activate our action and we can call it using server side code, client side code and using other Workflow and dialogs as well (new feature in CRM 2015). We ca use following code call our action:

//we have written method to get CRM service object
IOrganizationService service = connection.GetCRMService();
//retrieve account record using that we want to create contact
Entity accountObj = service.Retrieve("account", new Guid("699D9F32-9B10-E511-80FD-C4346BAD3138"), new ColumnSet(true));

//Create organization Request object and pass action name as parameter
OrganizationRequest Req = new OrganizationRequest("new_actiondemo");
Req["ParentAccount"] = accountObj; //passing our first parameter
Req["Salesperson"] = new EntityReference("systemuser", new Guid("90322292-C8EC-4A72-8B32-B79DEF7DD31C"));
//use execute method to call action
OrganizationResponse Respons = service.Execute(Req);

After execution of the code we can see in CRM contact record is created by action like below:


So in above example we show if we need to pass multiple parameter we can use Entity object instead of passing field value one by one and entity reference is used to for passing a single entity reference instance.

7 thoughts on “Using Actions in Microsoft Dynamics CRM 2015

  1. Pingback: Zsolt Zombik Dynamics CRM Blog’s Top CRM Articles of the week – 10th Jul - Microsoft Dynamics CRM Community

  2. Manu

    Very nice post. Apologies if this is a stupid question – Can you please tell me where the code is placed? Is it in Account entity as a JavaScript resource or somewhere else?

  3. Pingback: Hosk’s Top CRM Articles of the week – 12th October – Hosk's Dynamic CRM Blog

Leave a Reply

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