getSelectedItems() not working on Wizard?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'm new to Skuid, and trying to figure out why this code is working fine as a mass action on a table, but shows arguments[0].list as undefined when used as an action on the Next Step button of a Wizard.

The table with the mass action is the same table in the first step in the wizard. If the arguments aren't getting passed properly to the Wizard, how can I make that happen?

Here's the code:
var idsSelected = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){ 
   return item.row.Id; });

var ids=idsSelected.join(",");

window.alert(ids);
Photo of Samuel Cohen

Samuel Cohen

  • 332 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of JG GBC

JG GBC

  • 694 Points 500 badge 2x thumb
Hi Samuel

Try to run this:

var model = skuid.$M('modelName'),
ids = [],
$ = skuid.$;

$.each(model.registeredLists,function(){
skuid.$.map(this.getSelectedItems(),function(item){
ids.push(item.row.Id);
});
});

ids.join(',');

window.alert(ids);
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
The Snippet you were using previously relied on a List to be passed in context --- which you will get if you're in a Mass Action Snippet. However, from a Wizard Step Button, there's no "context" List, so arguments[0].list is not going to work. What you can do instead is this: 

1. Find (and/or modify) the Unique Id of the Table from which you are trying to get selected items. So for example let's say its Unique Id is "MyTable".
2. Modify your Snippet to be this:

var TABLE_UNIQUE_ID = 'MyTable';
var list = skuid.$('#'+TABLE_UNIQUE_ID).data('object').list;
var idsSelected = skuid.$.map(list.getSelectedItems(),function(item){ 
   return item.row.Id;
});

var ids=idsSelected.join(",");

window.alert(ids);
(Edited)
Photo of Samuel Cohen

Samuel Cohen

  • 332 Points 250 badge 2x thumb
Thanks Zach - that's helpful to know about arguments[0].list not working there. I used your code, but it's still showing an error of "Cannot read property 'data' of undefined."

Just to confirm, here's the snippet code:
var TABLE_UNIQUE_ID = 'campaignSelectTable';
var list = skuid.$('#'+TABLE_UNIQUE_ID).element.data('object').list;
var idsSelected = skuid.$.map(list.getSelectedItems(),function(item){ 
   return item.row.Id; 
});
var ids=idsSelected.join(",");
window.alert(ids);
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
I made a copy/paste error --- the ".element" in line 2 is not supposed to be there. I edited my answer above to remove this part.
Photo of Samuel Cohen

Samuel Cohen

  • 332 Points 250 badge 2x thumb
Thank you Zach! That totally works. I'm trying to take those IDs and apply them as a value in a condition on another model, in the context of a wizard.

1: Select the Campaigns you want
2: Click Next Step, which runs a snippet which sends those Campaign IDs as the value to a condition on a CampaignMember model
3: On the next page, there is a table using the Campaign Member model, only showing Campaign Members whose Campaign IDs are in that set of Campaigns from Step 1

This would be awesome if we can make it happen in Skuid. I really appreciate your help here!