Tap Forms JavaScript Scripting 102
Forms, Records, Fields, Values
by T. L. Ford

Section 10: Linked Form Records

Up until now, we've only been looking at Form scripts, i.e. scripts stored with the form, not Field scripts.

Let's look at a simple Field script that builds a list of things from its linked form data.

I updated our Rescue Animals database to include a 'Foster Location' form, and I linked the animals to where they are/were located. (I'm unsurprised to find Snoopy at Charlie's House and equally unsurprised to find Dogbert at Lucy's.)

We want to display, right on the 'Foster Location', a list of animals that haven't been adopted yet.

I added a field of type 'Script' to display the list and named it 'Not Adopted Yet'.

Whatever our function returns will be displayed in the field on the form.

We'll start with a basic function shell.

We want the linked field, so I click on 'Rescue Animals' in the Available Fields list.

Then I click on the 'Insert field into script' button.

Notice that awesome shortcut to the currently active record: record.

That link field is returning an array of the linked records.

This is how the linked form field is set up.

We have that fancy report code we wrote earlier for looping through our records and building a pretty cat/dog report and we have syntax to filter the arrays. Let's do what ALL of the greatest programmers do and go copy and paste it, tweak variable names.

There's a 'Child records loop' snippet you could insert and modify, but we already have working code so we should use it.

Enthusiastic people who run this code may notice that this script prints to the Results window, not the Console window.

That's because we are on a Field script and these return a value that is then displayed on the record.

If we toggle that 'Update records when saving' button on and then save it, we see our 'Not Adopted Yet' list.

If we add a new animal and then link that animal on the 'Foster Location' form, the 'Not Adopted Yet' list automatically updates.

NEXT - Section 11: Review