Get PK id's from multiselect

What is the fastest and best way to get an array with pkid’s from selected records?

I don’t want to use:
forms[controller.getName()].foundset.getSelectedRecords();
Because I only need the pk id’s

When I use forms[controller.getName()].foundset.getSelectedIndexes(); I need to loop the array and get the pk’id’s.

Is there a way to just retrieve the pk id’s from the selected records?

Thanks

Hi, I believe the next code it should work.
Best regards

var selection = forms[frm].foundset.getSelectedIndexes();
for (var x in selection) {
     recSelect = forms[frm].foundset.getRecord(selection[x])
     var idRec = recSelect.id;           // --- If id is the name of the pk.
}

I think the first option (the one which you do not want to use) is the best, as it gets you the JSRecord objects and on those you can get the PK’s using the function JSREcord.getPKs.

Paul

Thanks :D

Just what I needed!

pbakker:
I think the first option (the one which you do not want to use) is the best, as it gets you the JSRecord objects and on those you can get the PK’s using the function JSREcord.getPKs.

Paul

True.

Thanks for the input, for now I will go for a mix :D

function testbutton()
{
	var $arr_pkids = new Array();
	var $selectedIndexes = forms[controller.getName()].foundset.getSelectedIndexes();
	for (var $i in $selectedIndexes) {
	     $arr_pkids.push(forms[controller.getName()].foundset.getRecord($selectedIndexes[$i]).getPKs()[0]);
	}	
	application.output("Selected records: " + ($arr_pkids));
}

use what paul told you, thats a way better solution
Now you loop and get the records again from the foundset instead of just doing 1 get.

var $arr_pkids = new Array();
   var $records= forms[controller.getName()].foundset.getSelectedRecords();
   for (var $record in $records) {
        $arr_pkids.push($record.getPKs()[0]);
   }