Trigger plugin using Action

actions

There are many scenarios that we needs to trigger plugin from ribbon / command bar. For this kind of scenario what we do, we create dummy entity and then call some message from JavaScript of  that dummy entity to trigger our plugin (you can explore this example from here ). This is what we do for MS CRM 2011, but from MS CRM 2013 onward, Microsoft CRM introduced ‘Action’ process.

Using Action we can trigger plugin, steps for that are …

  1. Get Process.js from here ‘https://processjs.codeplex.com/‘,  add it in MS CRM
  2. Register ‘Process.js’ on form where your plugin is going to trigger, ref below example
  3. 1
  4. Create an empty ACTION process, ref below example, create action on same entity where you want to trigger your plugin
  5. 2
  6. Create JavaScript function ref. below example, which will trigger Action on button click.
  7. //to trigger action 
    function triggerAction() {
    
     Process.callAction("***_generateQuoteDocument",
     [{
     key: "Target",
     type: Process.Type.EntityReference,
     value: { id: Xrm.Page.data.entity.getId(), entityType: "quote" }
    
     },
     {
     key: "Test",
     type: Process.Type.String,
     value: "Something"
     }],
     function (params) {
     alert(params[0].value);
     // Success
     for (var i = 0; i < params.length; i++) {
     alert(params[i].key + "=" + params[i].value);
     }
     },
     function (e) {
     // Error
     alert(e);
     },
     Xrm.Page.context.getClientUrl()
     );
    }
  8. Open plugin registration tool, and register plugin, you will notice once difference here is, you will get Action name in message box, just register plugin on that message, ref. below example
  9. 3
  10. Now you will get entity details in plugin as EntityReference, ref. below screen shot
  11. 4
  12. That’s it.

Thanks.

Explore more about Action here 

https://technet.microsoft.com/en-us/library/dn531060.aspx

https://technet.microsoft.com/en-us/library/dn949331.aspx

 

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s