How would I loop through new & existing rows in a table in a snippet?

  • 1
  • Question
  • Updated 6 years ago
  • Answered
Building on the case outlined in a previous post, I have a page showing details of object/model "A". I want users to see a table below that represents a junction object between object "A" and object "B". The record being linked to in object "B" is the same for all of the records in the table, and I can retrieve It's ID from existing models on the page. Since the object "B" record is implied, I don't want to users to have to select it, but I do need the system to be able to populate that field upon save of a new record in the table.

Seems like I need a snippet for saving that can set this value on any new records then save the model. How would I identify and loop through the new records to set the value?
Photo of Peter Bender

Peter Bender, Champion

  • 6,246 Points 5k badge 2x thumb

Posted 6 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Official Response
Hi Peter,

To loop over all records in a model, whether new or not, you need a reference to the model. You do this by using the following code.

var mymodel = skuid.model.getModel('ModelName');

Once you have a reference to the model, you can loop over and update the rows in it with the following code. Since jQuery comes with skuid, we can leverage it.


Once you're done updating the rows, you can save the model.;