I want to create a JavaScript button to use on list views that when clicked captures a list of the values of a field on all the selected records. GETRECORDIDS returns a set of IDs of selected records. I want to get a set of values that are in a certain field.

For example, if I put the button on a list view of contacts, I would want to get a list of all the email addresses for the selected contacts. Not all of the users have API enabled so I can't query the values after collecting the IDs.

Is there a way for me to get a set of all the email addresses using a JavaScript button?

  • I think you'd have to proxy it to a StandardSetController, use getSelected and then query for those records. Or use a Jquery selector / Javascript to grab them from the DOM? Commented Dec 5, 2012 at 16:29

1 Answer 1


You can start with something like this:

var parentForm = this;
while(parentForm.nodeName.toLowerCase() != 'form'){
    parentForm = parentForm.parentNode;

// we have the form, the table is in 2nd div inside it
var table = parentForm.lastChild.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0];
var rows = table.getElementsByTagName('tr');

//alert(rows.length); // this contains only visible rows (5 by default)!

// first row we can skip, it's a header row really.
var columnindex = 1;
var values = [];

for(var i = 1; i < rows.length; ++i){
    var row = rows[i];
        var value = row.getElementsByTagName('td')[columnindex].innerHTML;

if(values.length > 0){
} else {
    alert('nothing was selected');

It's essentially screenscraping though and very limited:

  1. If related list has 5+ items but user's preference is to display only 5 - bad luck.
  2. It has hardcoded column index so you must be very careful if you'll ever edit the related list (or expand the code so it checks the header row)
  3. Did I mention it's screenscraping?
  • Ugh. I definitely don't want to screenscrape. Commented Dec 14, 2012 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .