BUTTON(RIBBON) TO CALL PLUGIN (PASS PARAMETERS AND RECEIVE RESULTS)
At some point on the roadmap of every Dynamics 365 (CRM) developer’s life, one must have wished to press a button to call a Plugin.
A combination of Custom Actions introduced in CRM 2013 and webapi introduced in CRM 2016 made this wish very easy. Developers have used different techniques to achieve the same goal e.g. creating records of dummy enttities or updating dummy fields of an entity to call plugins.
There is a smarter way to do so using Custom Actions and here is how we can do it:
Our solution consists of 4 main parts:
1. A CRM custom action with input/output parameters (it can be bound(on an entity) or unbound(global) depending on your requirements)
2. A plugin registered on the custom action (this will perform the task and will set the outpur parameter with results)
3. Script under the button: this will use webapi to call custom action sending input parameters if necessary and will receive the results as output paramters
4. Ribbon button to call the javascript function