Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Script linked table loop
- This topic has 4 replies, 2 voices, and was last updated 5 years, 10 months ago by Brendan.
-
AuthorPosts
-
January 16, 2019 at 1:38 PM #33462
Gianantonio FiannaccaParticipantPlease, can you post a little example how looping a linked table?
I don’t found field reference in a main record to identify linked table; instead I see fields in a linked table. But I don’t know how loop secondary records table.
Thank,
GianantonioJanuary 16, 2019 at 2:51 PM #33463
BrendanKeymasterHi Gianantonio,
There’s a snippet that does this for you.
Just tap on the Child Records Loop snippet when you have a child field selected on the Script Edit window. If you’re using iOS, tap the snippet first, then Tap Forms will ask you which field you’d like to select. When you select the field, Tap Forms will generate the code for you that loops through the Table field records.
Also you can double-click on a Table field or Link to Form field header and Tap Forms will write the code for you to get the child records.
January 16, 2019 at 8:25 PM #33472
Gianantonio FiannaccaParticipantThank, it work.
May i suggest a modify?This is code automatically generated:
function recordsLoop() {
var secondario = record.getFieldValue(‘fld-a4ffc2006b8a4d4fb6b2e7efd8893519’);
for (var index = 0, count = secondario.length; index < count; index++){
var descsec = secondario[index].getFieldValue(‘fld-6a4451ec6845458d858e0e2cd5f098bb’);
if (descsec) {
// do something
}
}
return;
}This is code I prefer to improve reading:
var descsec_id = ‘fld-6a4451ec6845458d858e0e2cd5f098bb’; // this is automatically generated
var secondario_id = ‘fld-a4ffc2006b8a4d4fb6b2e7efd8893519’; // this is not generated!!!function recordsLoop() {
var secondario = record.getFieldValue(secondario_id);
for (var index = 0, count = secondario.length; index < count; index++){
var descsec = secondario[index].getFieldValue(descsec_id);
if (descsec) {
// do something
}
}
return;
}January 17, 2019 at 12:19 AM #33474
BrendanKeymasterGood idea. Just working on the change now.
January 17, 2019 at 12:35 AM #33475
BrendanKeymasterSo I modified the Snippet to generate this output now:
function recordsLoop() { var contacts_id = 'fld-5d42ca3c077447cc8dfdc0051b5e1a66'; var full_name_id = 'fld-b2f115ea90c24fce95eb19fad66eda16'; var contacts = record.getFieldValue(contacts_id); for (var index = 0, count = contacts.length; index < count; index++){ var full_name = contacts[index].getFieldValue(full_name_id); if (full_name) { // do something console.log(full_name); } } return; } recordsLoop();
Thanks again for the suggestion. It was a good one :)
-
AuthorPosts
You must be logged in to reply to this topic.