Using result of script field in search

Viewing 4 reply threads
  • Author
    Posts
  • August 24, 2025 at 12:05 PM #52867

    Peter Riley
    Participant

    My home brew database has a record for each beer recipe and each record has a table field where I log each brew of that recipe. One of the table’s fields is Quantity (number of bottles produced) per brew, so there are usually several rows in the table. The main recipe record has a Total field that is a script field to sum the remaining bottles from the table Quantity field with this code:

    record.getTotalOfLinkedFieldForField(linkedFieldID, fieldID);

    to populate it, where linkedFieldID is the table ID and fieldID is the Quantity field.

    I have a search named ‘Brew Some More’ to filter the records where Quantity = 0. That works OK, but if I edit the search criterion to be ‘Quantity is less than or equal to 2’ I get beers with 11 bottles remaining, but not those with 4 or 8. I suspect I have a data type issue maybe?

    Attachments:
    You must be logged in to view attached files.
    August 24, 2025 at 3:07 PM #52869

    Daniel Leu
    Participant

    Is the table you’re revering to the Inventory table? Looks like you just discovered a but where the TFF file doesn’t contain the fields inside the table.

    In your script field, it might be that the result is interpreted as a string and not an number. You might want to try to use return parseInt(total); and set the return type accordingly. I don’t have the content of your script field so I’m just imagine what you might do.

    Good luck and cheers!

    Attachments:
    You must be logged in to view attached files.

    Cheers, Daniel

    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    August 25, 2025 at 1:53 AM #52874

    Peter Riley
    Participant

    Thanks Daniel and yes, it’s the Inventory table, which should look like the attachment.

    My field script for the Total field is this: record.getTotalOfLinkedFieldForField('fld-ac6d9e3d03ae441994ff64b37ebba4f4', 'fld-b02673a0fe39401583e737a0876998e6');

    The interesting thing is that if I change the brew that currently has a total of 11 remaining bottles to a number less than 10 it works, so I guess you’re right in that the Total field is being interpreted as a string and therefore the search for a number less than 3 fails because it parses the first ‘1’ of ’11’ only. Using return parseInt(total) as follows doesn’t seem to make a difference (the console in the editor correctly displays 11):

    function return_total() {
    
    var total = record.getTotalOfLinkedFieldForField('fld-ac6d9e3d03ae441994ff64b37ebba4f4', 'fld-b02673a0fe39401583e737a0876998e6');
    return parseInt(total);
        }
    
    return_total();

    Thanks

    • This reply was modified 2 weeks, 5 days ago by Peter Riley.
    Attachments:
    You must be logged in to view attached files.
    August 25, 2025 at 9:20 AM #52879

    Brendan
    Keymaster

    I’ve just fixed the bug with exporting a TFF file for a form that has a Table field in it.

    August 25, 2025 at 9:33 AM #52880

    Brendan
    Keymaster

    Peter,

    Your Result Type for your Total Script field is set to Text. Try setting it to Number and see if that solves your issue.

    Thanks,

    Brendan

    August 25, 2025 at 10:58 AM #52882

    Peter Riley
    Participant

    Ah, thanks Brendan. Apologies – I hadn’t spotted that switch before.

    All working fine now.

    Regards

Viewing 4 reply threads

You must be logged in to reply to this topic.