loop through rows in a model

edited December 11, 2018 in Questions
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;
for(i=0;i<allOutstandingItemData.length;i++){
var itemRow = itemData[i];
}

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    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],
        $ = skuid.$;
    var CHECKBOX_FIELD = "My_Checkbox__c";
    var idsOfRowsThatAreChecked = [];
    var OutstandingItemModel = skuid.model.getModel('OutstandingItem');
    $.each(OutstandingItemModel.data,function(i,row){
       if (OutstandingItemModel.getFieldValue(row,CHECKBOX_FIELD)===true){
            idsOfRowsThatAreChecked.push(row.Id);
       }
    });
    // Display the ids of the rows that are checked
    console.log(idsOfRowsThatAreChecked);
  • edited September 19, 2014
    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', }


  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    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. 
  • edited August 16, 2018
    its ok, I worked it out, I changed the apex input param to accept Id[] instead of String.

    Thanks
  • edited September 1, 2016
    one more question would you know how to close the popup from the javascript snippet?
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    skuid.$('.ui-dialog-content').last().dialog('close');
  • Rob HatchRob Hatch 💎💎💎
    edited September 1, 2016
    Valid question that should be searchable. Please reference the new topic here: Close a Popup from a Javascript Snippet
  • edited August 16, 2018
    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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!