Advice on script triggering

Viewing 11 reply threads
  • Author
    Posts
  • January 1, 2019 at 4:28 AM #33068

    Ian Heath
    Participant

    I’m making a cataloguing database for things like DVDs and am using the example script in the script help section of this website (which uses the barcode/UPC to do a lookup to the Internet to get the product details). What I would like to do is to have a button on the form to trigger the script (rather than having to select it from the menu, which I feel is less intuitive/convenient), but I don’t think this is possible? (I would love that as an enhancement!). I’ve read a few forum posts on the subject of script updating and aren’t sure what it’s best to do. Since the service used for the lookup is limited re. the number of lookups (for the free service) I want to limit the quantity of lookups, i.e. I was thinking of writing per field scripts that returned the specific value based on when the barcode/UPC value changed, but this would increase the number of lookups. Also I would like to be able to choose when to do a lookup, hence the desire for a button/trigger. Thanks in advance.

    January 1, 2019 at 11:15 PM #33074

    Brendan
    Keymaster

    Hi Ian,

    On a custom layout you can add a button which you can click on to trigger a Form Script.

    Click the custom layout, then the Layout button. At the top-right of the Layout Inspector panel you’ll see a “button” button. Click on it, then drag out a rectangle on your custom layout. Now on the Layout inspector panel you can set the Form Script to trigger when you click the button.

    Hope that helps!

    Brendan

    January 2, 2019 at 2:52 AM #33080

    Ian Heath
    Participant

    Thanks Brendan, I should have mentioned that I’m using the iOS application. Assume this functionality is only on macOS?

    January 2, 2019 at 1:40 PM #33094

    Brendan
    Keymaster

    Oh yes. That’s right. Sorry about that. Custom layouts are only available on macOS and that’s why there’s no button function in the iOS version. You have to use the Run Script menu to activate a Form Script on iOS.

    January 2, 2019 at 4:08 PM #33101

    Ian Heath
    Participant

    Any plans to add this to iOS versions, or if not layouts at least a simple button option in place of a field to trigger a given script. I think that’d be a great enhancement.

    Cheers Ian

    January 2, 2019 at 7:47 PM #33108

    Brendan
    Keymaster

    Well, you could simulate a button by adding a Checkmark field to your form and then reference that Checkmark field in your script. When you tap the Checkmark field, the script will run.

    January 3, 2019 at 3:14 AM #33116

    Ian Heath
    Participant

    Ah that’s an excellent idea. I tried it and it’s not working though, no-doubt an issue with me.

    I have a Form Script with a reference to the check mark field in it:

    var upc_lookup_id = ‘fld-8b5f99cd185044f8a0b35204db4c86ac’;

    Which I assumed was sufficient to trigger the script when that field is updated?

    Assume I’m missing something :-)

    January 3, 2019 at 5:12 AM #33123

    Ian Heath
    Participant

    Fixed it, I was using a form script not a field script (assume it has to be the latter?).

    Also I didn’t have this line in the script which I think is needed?

    record.getFieldValue(upc_lookup_id);

    Thanks

    January 3, 2019 at 5:49 PM #33134

    Brendan
    Keymaster

    Yes, it would have to be a Script Field and not a Form Script. That’s because Form Scripts all are run manually whereas a Script Field is run when a value it references changes.

    yes, the record.getFieldValue(field_id) reference is what tells Tap Forms that script is referencing that field, so when that field changes its value, run the script that references it.

    November 2, 2020 at 2:26 PM #42484

    Brecht DHeere
    Participant

    Hi,

    Why do I need to refresh before the record is deleted?
    I’m using a field script on the Mac version.

    Thanks,
    Brecht

    var checkmark = record.getFieldValue (‘fld-cf7c770a0bb04dc7922e79b24467bbd1’);
    if (checkmark) {
    form.deleteRecord(record)
    }
    form.saveAllChanges();

    November 5, 2020 at 12:20 AM #42494

    Brendan
    Keymaster

    This is something I’m fixing for a future upgrade.

    November 5, 2020 at 12:52 AM #42495

    Brecht DHeere
    Participant

    Thanks Brendan

Viewing 11 reply threads

You must be logged in to reply to this topic.