Help with calculation to display text from one field to a different field

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Help with calculation to display text from one field to a different field

Viewing 1 reply thread
  • Author
    Posts
  • August 22, 2024 at 11:10 PM #51038

    tapforms_user
    Participant

    Hi I am trying to display text from a field in a table to a field on the same form but not in the table.

    The formula should be simple: in the calculation field, using the left panel that shows all available fields, select the field in the table that I want to display.

    But when I do this, the formula prepopulates a “TOTAL” in front of the field name. This is not what I want. I don’t know why it wants to give me a total when I am looking for the value of the field, not a total for the column.

    I have tried a script with the field ID from the table but it does not work because I am writing to a field outside the table. Maybe a workaround is if someone can show me the syntax to reference table field ID ‘xyz’ for example, noting I need to pull this value into a field that is not in the table (but it is on the same form).

    Any help is most welcome!

    • This topic was modified 4 months ago by tapforms_user. Reason: Updated post title
    August 23, 2024 at 7:28 AM #51040

    JScottA
    Participant

    The following is from the Tap Forms 5 Assistant. Your mileage may vary:

    The issue you’re encountering is due to how Tap Forms handles table fields when referenced in calculations. When you try to reference a field inside a table from outside that table, Tap Forms automatically assumes you want to perform an aggregate operation, like a total, which is why it prepopulates with “TOTAL.”

    ### Workaround:
    If you need to display the value of a specific field within a table but outside of that table, a script is indeed the way to go. Here’s a simple example of how you might achieve this:

    #### Step-by-Step Guide:
    1. **Create a Script Field:**
    – In your form, add a new field and set its type to “Script.”

    2. **Write the Script:**
    – Open the script editor for the new Script field.
    – Use the following JavaScript code as a starting point:

    `javascript
    // Retrieve the table field
    var tableField = record.getFieldValue(‘TableFieldID’); // Replace ‘TableFieldID’ with your actual table field ID

    // Access the specific record within the table (assuming you want the first one)
    var specificRecord = tableField[0]; // This accesses the first row in the table

    // Retrieve the field value within that record
    var value = specificRecord.getFieldValue(‘SubFieldID’); // Replace ‘SubFieldID’ with the ID of the field you want to retrieve

    // Return the value to be displayed in the script field
    value;
    `

    3. **Adjust for Your Needs:**
    – Replace 'TableFieldID' and 'SubFieldID' with the actual field IDs from your table and the specific field you want to display.

    4. **Save and Test:**
    – Save the script and see if the value from the table field now appears in the script field outside the table.

    This approach allows you to pull and display data from a specific row in a table field without triggering the default aggregation (e.g., TOTAL).

    ### Reference:
    This technique leverages Tap Forms’ scripting capabilities, which you can further explore and customize based on your specific needs [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w). If you need more detailed scripting assistance, you might refer to the [Tap Forms Scripting 101](https://www.cattail.nu/tap_forms/tap_forms_scripting_101/index.html) for advanced customization.

Viewing 1 reply thread

You must be logged in to reply to this topic.