loop through rows in a model

Using something similar to the code below how can I write a javascript snippet to loop through all the data in a Model displayed in a table.

Basically I have 3 columns and one of the columns contains checkboxes.
The user can check any of the checkboxes for each row.
Once they click on the button, it calls the snippet, which should then loop through and get the Id’s of the rows that have been checked.

(NB when looping through to check each row, to see what has been checked if the data has not been saved yet, can we still get the Id’s of the checkboxes that have been checked?)

var params = arguments[0],
    $ = skuid.$;

var OutstandingItemModel = skuid.model.getModel(‘OutstandingItem’);
var allOutstandingItemData = ;
allOutstandingItemData = OutstandingItemModel.data;
var i = 0;
var itemRow = itemData[i];

Rows that have not been saved yet still have “temporary Ids”, so yes you can get those rows’ Ids as well.

If your checkbox field name is “My_Checkbox__c”, then you could do something like this:

var params = arguments[0],<br>&nbsp;&nbsp;&nbsp; $ = skuid.$;<br>var CHECKBOX_FIELD = "My_Checkbox__c";<br>var idsOfRowsThatAreChecked = [];<br>var OutstandingItemModel = skuid.model.getModel('OutstandingItem');<br>$.each(OutstandingItemModel.data,function(i,row){<br>&nbsp; &nbsp;if (OutstandingItemModel.getFieldValue(row,CHECKBOX_FIELD)===true){<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;idsOfRowsThatAreChecked.push(row.Id);<br>&nbsp; &nbsp;}<br>});<br>// Display the ids of the rows that are checked<br>console.log(idsOfRowsThatAreChecked);

Thanks that worked a charm.

Any idea how to pass the array of Id’s to an apex webservice call as the below doesn’t work:

var sResponse = new String(sforce.apex.execute(“AppSummary”,“packReceivedButton”,{OutstandingItems:idsOfRowsThatAreChecked}));

I get the below error, thanks

{faultcode:‘soapenv:Client’, faultstring:‘Element {http://soap.sforce.com/schemas/package/AppSummary}OutstandingItems invalid at this location’, }

Check your Web Service call definition to make sure that you’re passing in parameters exactly as your Web Service call is expecting them. Especially case sensitivity. If your parameter name is outstandingItems in your Web Service (camel-cased), then it will need to be outstandingItems in your web service call in JavaScript. 

its ok, I worked it out, I changed the apex input param to accept Id instead of String.


one more question would you know how to close the popup from the javascript snippet?


Valid question that should be searchable. Please reference the new topic here: Close a Popup from a Javascript Snippet

How do I need to resolve this issue same as above, when I am using above code, only pushed one record , not able to send to list of ids param , can u share a piece of code.