Trigger Mass Action via Javascript Snippet

Is there any way to trigger a mass action on a table via Javascript Snippet.

I have a table with a mass action attached to it.  I’d like to be able to trigger that action in a snippet.


There’s likely a better way, but I was able to do this by using jQuery to target the button which normally triggers the desired mass action and then forcing a click on it. Here’s my code:

var $ = skuid.$,
    action = arguments[0].action,
    list = arguments[0].list,
    model = arguments[0].model; // Force all checkboxes (for each table row) into checked state
$('#sk-3GF2wd-4635 input[type=checkbox]').prop("checked",true); // Trigger a click on the button which triggers the mass action
$("#followupTable div.nx-massactions div:eq(0)").click(); 

I found the selector for the checkboxes and the mass action using Chrome’s devtools. There are a lot of guides around if you’re unsure of how to do this yourself. Here’s a decent one.

Here’s how I attached the snippet to a save button on my layout:

Hope this helps and I’m happy to help clarify if needed. Also curious if anyone found a “nicer” way of doing this.

Thanks for posting this! You might find this method a little “nicer”, as it doesn’t require manually picking out DOM elements:

var $ = skuid.$, list = arguments[0].list, selectedItems = list.getSelectedItems();

selectedItems should return information about the associated element, row, etc.
Hope this helps!