Maintaining Linked Field Values via Scripting

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Maintaining Linked Field Values via Scripting

Viewing 3 reply threads
  • Author
    Posts
  • May 19, 2020 at 5:43 PM #40646

    Larry Zappaterrini
    Participant

    Hello!

    I’m working on a script to maintain a linked field via the value of another field both on the same form. The field that will be getting modified is a simple text field that will contain ; delimited string tags. The linked field that is based on those tags references a separate form with entries that are keywords. My goals is to parse the tags and have the linked field’s values set based on those tag values.

    I have the script to do this pretty much working with a couple of caveats. The script removes all of the entries in the linked field via removeRecordFromField(), parses the tags, looks them up in the linked table, and adds them to the linked field using addRecordToField(). The script executes as expected but the linked field doesn’t seem to be updated. If I open the keyword form and go back to the main form the linked field the shows the updates. Also, if I add a new keyword into the tag field along with an existing one, the new keyword is created in the linked form, but the new one is the only value in the linked field.

    Has anyone seen similar behavior in this type of scenario that might have some advice?

    Thanks!

    May 19, 2020 at 11:49 PM #40653

    Brendan
    Keymaster

    Hi Larry,

    Are you remembering to call form.saveAllChanges(); after you return from your script? I’m sure you are. That should generate an update notification to update the record display.

    Maybe if you email me an archive of your parent form then I could take a look at it and run it through the debugger to find out why it’s not updating the child record.

    Thanks,

    Brendan

    May 20, 2020 at 11:52 PM #40665

    Sam Moffatt
    Participant

    I was running into an issue where the record state for a Link field wasn’t updated properly within a script context. I ended up solving it by adding an explicit form.saveAllChanges() after I did a addRecordToField(). If I didn’t do that, I ended up in these weird situations where the inverse relationship metadata wasn’t setup properly which caused weirdness with script fields that were triggered. Might I suggest adding it not just at the return but each time you manipulate a link field.

    May 21, 2020 at 7:58 AM #40668

    Larry Zappaterrini
    Participant

    Thanks for the replies. Your suggestions both led me to a solution. Strategically placing form.saveAllChanges() corrected those inconsistencies. I did have to rework my overall logic though. The simplest approach I felt would be to delete all of the records from the linked field rather than trying to determine if any of the entries should be preserved. It seems that deleting takes precedence over adding when dealing with the same record in the linked field regardless of the order they occur in the code. I ended up only deleting entries that are not present in the tag field and now it is working as desired.

    Thanks for the assistance and adding such an awesome feature to Tap Forms!

Viewing 3 reply threads

You must be logged in to reply to this topic.