Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 331 through 345 (of 2,989 total)
  • Author
    Search Results
  • #51041
    David Oxtoby
    Participant

    I have a Form for which I need to delete all its records and then import them afresh from a CSV file (I use defined presets when importing Records in TapForms). The CSV file gets generated outside of TapForms, and I’m just wondering if there’s a semi-automated way of doing this via a script. Any pointers are much appreciated.

    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.

    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 1 year, 5 months ago by tapforms_user. Reason: Updated post title
    #51033
    tapforms_user
    Participant

    Hi coming back to the more simple script. It’s working great thanks to your help. Now I would like to also add (concatenate) some fields from another table (but on the same form). I’ve tried using the field ID’s from both tables but it returns 1 or undefined.

    What I’d like to know is: Is it possible to concatenate multiple fields from 2 different tables? if yes, what must I add to the script?

    #51025
    Daniel Leu
    Participant

    Great that you got it working!

    To run the script automatically, you would need to create a field script. It’s just like another field, but has the script attached to it. Usually with a field script, you wouldn’t update a field in all records. Depending on the number of records, you might notice a performance issue.

    Cheers, Daniel

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

    #51024
    tapforms_user
    Participant

    There are two issues I see: “var value = record.getFieldValue(‘G2’);” and “record.setFieldValue(‘G’, resultG);”. Both functions expect a field id not a field name. So either you change it to “getFieldValue(‘fld-xxxx’)” with ‘xxxx’ being the number you get in the editor (click on the field, then ID), or use “record.getFieldValue(form.getFieldNamed(‘G2’).getId(), resultG);”, same for record.setFieldValue();. Additionally, after you set the value, you have to add a document.saveAllChanges(); to get your results into the database. Hope this helps.

    This is a huge help. Thank you! I tested your recommendations using another more simple script to concatenate different fields in the table – I had also been struggling with this. Switching to ID and adding the save changes fixed everything! Thank you! I had been battling with this for hours.

    How can I get the script to run automatically? I.e. to populate the destination field ID when data is entered into the fields it is pulling the data from.

    #51018
    B Hanson
    Participant

    Hello,

    I am trying to create a simple database; I am not a computer programmer or anything so I have no clue about scripting. I am not ever sure if this is the correct app for me.

    In short, I have two excel files that I’ve imported: one that has 500 company names and the other is a list of 300 contacts (all contacts on this sheet all work for the same consulting company).

    Contacts Spreadsheet:

    Those 300 contacts have columns such as “Client Lead 1,” “Client Lead 2,” “Security Lead 1,” “Security Lead 2,” “Sales Lead 1,” “Sales Lead 2.”  Person 1 (Bill Smith, for example) could be a Client Lead for, say, Bank of America, they could also be a Client lead for Chase, as well as a Security Lead at, say, Edward Jones & Citi. That is why I have to have multiple Client Lead and Sales Lead fields / columns for each contact.

    Company Spreadsheet:

    The 500 companies have columns that list things such as “industry vertical,” a “Client Lead,” “Security Lead” & “Sales Lead.”

    What I am trying to get to is:

    1) A comprehensive view where I can punch in an account name, say “Chase Bank,” see who are all the people that are on listed as either the Client Lead, Sales Lead and Security Lead on Citibank from the Account .xls

    2) On the Chase Bank example above, as Bill Smith is listed as the Client Lead,  I’d like to be able to click on Bill Smith and have it take me to his record on the Contact form, showing me all of the roles and contact details associated with him.

    Is this possible to tie them together? If so, let’s say I find out Bill Smith is no longer the Client Lead at Chase but instead is at Wells Fargo, do I need to update both the Client Form and the Account Form to reflect Bill’s addition to Wells Fargo and removal from Chase Bank?

    Thank you to anyone who can help as I am over my head.

    • This topic was modified 1 year, 5 months ago by B Hanson.
    #51011
    tapforms_user
    Participant

    Hi I’m new to Tapforms and really enjoying the product.

    I’m having some difficulty with a script to run in a table. It should run the calculation on column name “G2” and then return a number value in column “G” but instead it populates NaN in the fields of column G. I have checked that column G2 is set to field, which it is, and the values in column G are all numbers. Column G is of course set as a script.

    Can anyone perhaps see where I have gone wrong? Or perhaps this is a common error with a known tip to correct it?

    Edit: I added the script as an attachment in a text file as I am not sure how to copy it in here.

    • This topic was modified 1 year, 5 months ago by tapforms_user. Reason: Added script in text file attachment
    • This topic was modified 1 year, 5 months ago by tapforms_user.
    • This topic was modified 1 year, 5 months ago by tapforms_user.
    Attachments:
    You must be logged in to view attached files.
    #51010

    In reply to: Custom Number Fomats

    JScottA
    Participant

    From Tap Forms 5 Assistant:

    To assist the forum member in tracking weight and power consumption with the ability to add units (like lbs, amps, watts, etc.) and potentially include smart conversion features, here’s how you can achieve this in Tap Forms:

    ### 1. **Creating Number Fields with Suffixes:**
    – Tap Forms allows you to create number fields where you can manually enter values like weight (lbs), power (watts), and current (amps). While Tap Forms doesn’t inherently allow you to add a suffix directly within a number field, you can work around this by using a **Text field** to store the number along with its unit. For example, you might have a field called “Weight” where you store “20 lbs”.

    ### 2. **Creating a Calculation Field:**
    – You can create a **Calculation field** that performs arithmetic operations on your numeric fields. For example, you could have fields for Weight (lbs), Current (amps), and Power (watts), and then use a calculation field to perform any necessary computations based on these values.

    – **Example**: If you have separate fields for weight in pounds (Weight_lbs) and kilograms (Weight_kg), you can use a calculation field to convert Weight_kg to pounds:
    `
    Weight_kg * 2.20462
    `

    – This will automatically calculate the weight in pounds whenever you enter a value in the Weight_kg field.

    ### 3. **Smart Conversion Using Scripts:**
    – Tap Forms supports JavaScript, which you can use to create more advanced calculations or conversions. For instance, you could write a script that allows the user to input weight in various units (kg, oz, lbs) and then convert it to the desired unit.

    – **Example Script**:
    `javascript
    var weight_kg = record.getFieldValue(‘field_kg’);
    var weight_lb = record.getFieldValue(‘field_lb’);
    if (weight_kg != null) {
    record.setFieldValue(‘field_lb’, weight_kg * 2.20462);
    } else if (weight_lb != null) {
    record.setFieldValue(‘field_kg’, weight_lb / 2.20462);
    }
    `

    This script checks if the weight is entered in kilograms and converts it to pounds, or vice versa. You can expand this script to handle other units like ounces.

    ### Reference Information:
    – For more details on setting up calculation fields and using JavaScript in Tap Forms, refer to **pages 29-37** in the manual, which cover **Calculation Fields** and **Script Fields** [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w).

    By following the steps above, the forum member can track and convert units effectively within Tap Forms.

    #51008

    In reply to: Custom Number Fomats

    Daniel Leu
    Participant

    Lorenzo, have a look at the attached document. It shows you how to convert a weight unit from metric to imperial and vice-versa. Each input field you want to convert needs a corresponding formatter field which is a field script. This script uses a common form script to perform the conversion.

    In the past, I already did a fraction converter, so I thought that this is a nice exercise to build upon that.

    Hope this helps!

    -Daniel

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

    Cheers, Daniel

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

    #50997

    In reply to: Sum selection?

    JScottA
    Participant

    Good morning. Here is what the Tap Forms Assistant provided:

    To address the user’s request regarding summing selected entries from a numeric column in Tap Forms without needing to create multiple calculations:

    1. **Selecting Multiple Entries**: Tap Forms itself doesn’t directly allow summing only selected entries through its standard interface without scripting or creating calculations. However, there are workarounds depending on your workflow.

    2. **Using Filters**: One approach could be to use Tap Forms’ filtering and grouping functionality to narrow down your dataset to just the entries you want to sum. Once filtered, you could use the summary calculation options that display totals at the bottom of the list view (available in Multi-Column view).

    3. **Scripting**: If you frequently change the range of entries you want to sum, a more flexible solution would involve scripting. You could write a JavaScript function within Tap Forms that allows you to select different ranges or criteria and then dynamically sum the values. This script could be easily modified each time you need a new sum.

    4. **Summary Calculation**: For a non-scripting approach, if you have a common range of entries you select often, you could set up multiple summary calculations within Tap Forms. These could be pre-set for various ranges and simply toggled on or off as needed.

    For a deeper dive into summary calculations, see page 29 of the Tap Forms manual, which discusses the summary options available, including summing, averaging, and counting entries within a field.

    If you’re interested in the scripting approach, the Tap Forms Scripting 101 guide online would be a good place to start to create a custom script tailored to your needs.

    If you need further assistance setting up any of these methods or want more details on scripting, let me know!

    #50996

    In reply to: Sum selection?

    Daniel Leu
    Participant

    How about using savedSearch? Usually, I add a checkmark field to each record and use a savedSearch on this field.

    For whatever I want to do, I select the records in question, then go to the saveSearch with checkmark=1 and have just these records. Now you get the sum for the records.

    Additionally, I’ve a form script to clear the checkmark fields.

    Cheers, Daniel

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

    #50976
    JScottA
    Participant

    FYI…pasted Vitor’s original post into the assistant GPT. For the record, I liked Brendan’s very concise and to the point response better, for my typical requests. Anyway, here is the complete GPT response:

    To display numbers with two decimal places in your Tap Forms script, you can use JavaScript’s toFixed() method. Here is your script modified to ensure that numbers are formatted to always show two decimal places:

    `javascript
    function Third_Party_Charges_Csv() {

    // Fetch content from table
    var third_party_charges = record.getFieldValue(‘fld-021cfb3cc4f446ddbf5f9463c7b5d620’);

    // Define field ids from table columns
    const item_id = ‘fld-410bdf5d624a4651b8a803becd9c6578’;
    const cost_per_item_id = ‘fld-6cea4aa73ad44b6f91ba7f566e321790’;
    const number_id = ‘fld-95791fbc24bd4f3ca714756e5dd6a060’;
    const cost_id = ‘fld-a0be1b009c6a4a99a1784d36da134ee3’;

    var txt = [];

    // Loop over all entries and fetch field content.
    for (var n = 0; n < third_party_charges.length; n++){
    var third_party_charge = third_party_charges[n];
    var item = third_party_charge.getFieldValue(item_id);
    var cost_per_item = parseFloat(third_party_charge.getFieldValue(cost_per_item_id)).toFixed(2);
    var number = parseFloat(third_party_charge.getFieldValue(number_id)).toFixed(2);
    var cost = parseFloat(third_party_charge.getFieldValue(cost_id)).toFixed(2);

    // Format field content as desired
    txt.push((n+1) + “. ” + item + “: £” + cost_per_item + ” x ” + number + ” = £” + cost);
    }

    // Combine each formatted table row
    return txt.join(” – “);
    }

    Third_Party_Charges_Csv();
    `

    By using parseFloat() and toFixed(2), this script ensures that the cost_per_item, number, and cost fields are always displayed with two decimal places [oai_citation:1,javascript – Format number to always show 2 decimal places – Stack Overflow](https://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places) [oai_citation:2,javascript – How to format numbers? – Stack Overflow](https://stackoverflow.com/questions/5731193/how-to-format-numbers).

    #50967
    Victor Warner
    Participant

    I have a script where several fields are concatenated together including one which contains a number:

    
    function Third_Party_Charges_Csv() {
    
    // Fetch content from table
    var third_party_charges = record.getFieldValue('fld-021cfb3cc4f446ddbf5f9463c7b5d620');
    
    // Define field ids from table columns
    const item_id = 'fld-410bdf5d624a4651b8a803becd9c6578';
    const cost_per_item_id = 'fld-6cea4aa73ad44b6f91ba7f566e321790';
    const number_id = 'fld-95791fbc24bd4f3ca714756e5dd6a060';
    const cost_id = 'fld-a0be1b009c6a4a99a1784d36da134ee3';
    
    var txt = [];
    
    // Loop over all entries and fetch field content.
    for (var n = 0; n < third_party_charges.length; n++){
    var third_party_charge = third_party_charges[n];
    var item = third_party_charge.getFieldValue(item_id);
    var cost_per_item = third_party_charge.getFieldValue(cost_per_item_id);
    var number = third_party_charge.getFieldValue(number_id);
    var cost = third_party_charge.getFieldValue(cost_id);
    
    // Format field content as desired
    txt.push((n+1) + ". " + item + ": £" + cost_per_item + " x " + number + " = £" + cost);
    }
    
    // Combine each formatted table row
    return txt.join(" - ");
    
    }
    
    Third_Party_Charges_Csv();
    

    In the field it displays (as currency) as, eg 32.40, but in the script it shows as 32.4.

    Is there a way to make the script show numbers with two decimal places?

     

     

     

    • This topic was modified 1 year, 5 months ago by Brendan.
    • This topic was modified 1 year, 5 months ago by Brendan.
    #50963

    In reply to: Movie Library Template

    David Schwane
    Participant

    I did add the API values to the script.  And I can see the data echoed back in the console log.  I’ve tried a few different movies.

    When I get some time, I’ll try to debug, but thought I’d check to see if an update was already done.

    thanks for replying.

     

Viewing 15 results - 331 through 345 (of 2,989 total)