How can I get all of the record IDs from a model into a Javascript variable?

  • 1
  • Question
  • Updated 11 months ago
  • Answered
var payableModel = skuid.model.getModel('Accounts_Payable');
    var modelRows = payableModel.getRows();
    var selectedItems = modelRows.getField("id");

I would like "selectedItems" to contain all of the record IDs from the "Accounts_Payable" model.  Thanks in advance for any help!
Photo of Danny Hartley

Danny Hartley

  • 434 Points 250 badge 2x thumb

Posted 11 months ago

  • 1
Photo of Gyan

Gyan

  • 1,400 Points 1k badge 2x thumb
Hi Danny,

You can use:
Object.keys(payableModel.dataMap);

Thanks.
Gyan
Photo of Danny Hartley

Danny Hartley

  • 434 Points 250 badge 2x thumb
Thanks, Gyan.  That did the trick.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,014 Points 20k badge 2x thumb
Since dataMap is an internal cache, I would recommend using the following, which uses supported API methods:

var allRowIds = payableModel.getRows().map(function(row) {
   return payableModel.getRowId(row);
});