Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Script or calculation that enumerates entries from a table
- This topic has 3 replies, 2 voices, and was last updated 4 years, 7 months ago by Brendan.
-
AuthorPosts
-
April 11, 2020 at 7:22 AM #40296
Paolo SogonoParticipantHi Everyone,
I pretty new to TF5 and scripts. I hope someone can help my with my concern.
I would like assistance in making a summary field that enumerates individual items from a Table Field.
Form 1: Customers
Fields: Name, AgeForm 2: Products
Fields: Name of product, description, instructionsForm 3: Orders
Fields: Customer(link from Form), Date of purchase, Product (Table Fields copy records from Products)E.g. John Doe, orders the ff items: a) A4, b) pencils, c) erasers on 2 April 2020.
In the Orders Form these are displayed separately in rows in the Product Table (with corresponding price and description)
I want to have a separate summary field in the Orders Form that will output the ff: “A4, pencils, erasers.”
Example 2:
Orders are
1. A4, 500pcs, $10
2. pencils, 1pc, $0.5
3. A4, 500pcs, $10
4. ballpen, 1pc, $1Output is “A4, pencil A4, ballpen.”
I’m not sure if I was able to explain it clearly. Any help would be appreciated.
April 11, 2020 at 11:18 AM #40299
BrendanKeymasterHi Paulo,
You can do this with the Child Records Loop snippet that’s available to you.
Just select your Price field from your Table field on the Script Edit window, then double-click on the Child Records Loop snippet at the bottom-left.
Tap Forms will write you a function which loops through the records of the Table field. You can then enhance it to pick out other fields too.
Thanks!
Brendan
April 11, 2020 at 7:40 PM #40300
Paolo SogonoParticipantThanks for replying Brendan.
I’m absolutely new to Javascript. Is it alright if you upload an example working database which uses the child records loop snippet?
April 12, 2020 at 12:58 AM #40302
BrendanKeymasterDid you try double-clicking on one of your Table field sub-fields?
In my test I have a field called
testing
. It’s a Number field.Here’s the code that Tap Forms wrote for me:
function recordsLoop() { var table_id = 'fld-c433974d87de4bbca4eae626bc412408'; var testing_id = 'fld-e70eaf87dca24e49ae34cdc6b4c596ca'; var table = record.getFieldValue(table_id); for (var index = 0, count = table.length; index < count; index++){ var testing = table[index].getFieldValue(testing_id); if (testing) { // do something } } return; } recordsLoop();
Tap Forms will write the code for you when you double-click on a sub-field of your Table field.
-
AuthorPosts
You must be logged in to reply to this topic.