Senthil Murugan's Blog

Home » Uncategorized » Run Dynamic Action from JavaScript in Apex

Run Dynamic Action from JavaScript in Apex

Greetings, the below link explains how to call DA in Java script, very useful information.

Thanks to Jeff Eberhard

 

I don’t remember the use case but I do remember a time needing to call a Dynamic Action from some JavaScript code.  It may have been a situation where I wanted to execute some database code from JavaScript and thought it might be easier to put all that code in a Dynamic Action vs. the method of using AJAX to call an Application Process.

Whatever the case, there is a way that this can be done. 

TL;DR: A dynamic action can be defined to fire on a “Custom” event which can be triggered using the jQuery $.event.trigger(“<eventname>”) method.

I’ve create an example here

Basically a dynamic action is created with the When Event set to “Custom”.  When the Event is set to “Custom” a field prompting for the Custom Event is given.  The value for the Custom Event can be any name that we want to name our custom event.  In this example it is called “DAEvent”.  With the “Custom” event the dynamic action still requires the Select Type field.  Set the Select Type option to “DOM Object” and set the DOM Object field to “document”.  The dynamic true actions can then be added to perform any functionality desired.

To run the Dynamic Action we then call the jQuery $.event.trigger method with the name of the Custom Event that we defined in the Dynamic Action.  The following line will run the Dynamic Action we created (note that the value passed to the function is the name of the Custom Event we defined in the Dynamic Action).

$.event.trigger("DAEvent");

In the example we added the line to a JavaScript function defined in the page header which we call when we press a button.

Sometimes it’s amazing how this stuff works. Enjoy!!!

http://www.eberapp.com/pls/apex/f?p=BLOG:READ:0::::ARTICLE:1695400346724960

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

%d bloggers like this: