Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Importing values from all related records
Tagged: import values record
- This topic has 2 replies, 2 voices, and was last updated 3 years, 11 months ago by Daniel Leu.
-
AuthorPosts
-
January 25, 2021 at 8:31 AM #43290
EddyParticipantHi Folks!
I have a (hopefully) small issue …
In order to categories records, I use a many-to-many relationship. This allows me to change the names of the categories later, because the category name is the value of the first field in the related record. And in the related record I can see easily a list of all records, with are under a specific category. So, this is the advantage compared to a picklist.
But now I need to read out the category-names, so that I can use them in the mother record. Concrete, I want to script, so that I have a text field, with just list all the category names a specific record belongs to.
So, call my stupid, I find no way. Of course, I know how to import a field value from a related record. But how can I get a list of all the field values in the first field of all the records wich are related?
Thanks in advance, all the best, stay healthy!
Eddy
January 25, 2021 at 3:53 PM #43292
Daniel LeuParticipantFor my example, I have a
parent
form and achild
form and they are linked. The link field has the idfld-aaa
.function Childs() { // get all child records var childs = record.getFieldValue('fld-aaa'); // define id of name field of the child form let childNameId = 'fld-xxx'; // clean results formatted as an array let childNames = []; // loop over all childs for (child of childs){ // get name of child and add to result array childNames.push(child.getFieldValue(childNameId)); } // return child names as a comma separated string. return childNames.join(', '); } Childs();
I hope this does what you were looking for.
January 25, 2021 at 5:28 PM #43293
Daniel LeuParticipantHere is the same code again but this time it uses the new javascript iterator
map
:function Childs() { // get all child records var childs = record.getFieldValue('fld-c22501cc3910474aa1c59387fde30d82'); // define id of name field of the child form let childNameId = 'fld-8b8f3b0cd59b4b4c9180a8903685e7ee'; // get child names in a array let childNames = childs.map(function(i){ return i.getFieldValue(childNameId)}); // return child names as a comma separated string. return childNames.join(', '); } Childs();
-
AuthorPosts
You must be logged in to reply to this topic.