The Custom Action is an important tool in Microsoft Dynamics CRM architect belt. Here are some of the Custom Action key features:
- It can be called from both client & server side, enabling the SPoI approach (Implement once, consume anywhere)
- Supply a flexible, declarative business logic definition mechanism which can be called from other Processes as well as from custom code (unlike Plug-in)
- Can be extended with Custom Workflow Activities
- Can receive input parameters and return output parameters in a straight forward manner, similar to an Organization level Web Service
- Provide an improved UX, as Custom Action can be executed a-synchronously from entity forms, web resources and Ribbon/Command Bar controls without blocking the user UI
- You can bind server side logic to client side events, e.g. calling a Custom Action from an onChange or onSave event handlers
- Implement a chunky rather than chatty communication with the server, as Custom Action usually wraps multiple operations which otherwise require multiple API commands
With Microsoft Dynamics CRM 2016 Web API you can now execute a Custom Action in the most simple manner, which is demonstrated in the rest of this post.
- Define and activate a Custom Action in MSCRM 2016 Organization
My sample Action receives few parameters, creates a Lead record and returns the new record URL.
Note that this Action is defined for a global context. Also note the Action’s unique name and parameters names which are used in the following code.
The handleWebLead function defines the dyn_HandleWebLead Action name and parameters.
It than calls the generic activateCustomAction function to execute the Action and return the output result.
The Action is executed using XMLHttpRequest which is defined to execute synchronously.