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 - 286 through 300 (of 2,950 total)
  • Author
    Search Results
  • #51057
    JScottA
    Participant

    Nice thread and useful, too! Out of curiosity, I ran the script through the TF5 Assistant and got the following response. Any script-pros out there want to comment on the good and bad for the query I had for suggestions on making the above script (great work, btw) “better”?

    Improving the script can be approached from several angles: code organization, error handling, efficiency, and flexibility. Here are some suggestions to enhance the script:

    ### 1. **Error Handling Improvements**:
    – **Enhanced Error Logging**: Extend the error handling to log which line caused the error and possibly skip the faulty line rather than aborting the entire import.
    `javascript
    if (output.errors.length > 0) {
    output.errors.forEach(error => {
    console.log(Error at line ${error.row}: ${error.message});
    });
    return;
    }
    `
    – **Field Existence Check**: Before setting field values, check if the field exists in the form to prevent runtime errors if the field is missing.
    `javascript
    if (form.getFieldWithId(panelid_id)) {
    newRecord.setFieldValue(panelid_id, line[0]);
    } else {
    console.log(Field with ID ${panelid_id} does not exist.);
    }
    `

    ### 2. **Code Modularity**:
    – **Modular Functions**: Break down the script into smaller, reusable functions to handle tasks like creating a new record, setting field values, and parsing different data types. This will make the script easier to maintain and extend.
    `javascript
    function setFieldValue(record, fieldId, value) {
    if (form.getFieldWithId(fieldId)) {
    record.setFieldValue(fieldId, value);
    } else {
    console.log(Field with ID ${fieldId} not found.);
    }
    }

    function createNewRecord(data) {
    let record = form.addNewRecord();
    setFieldValue(record, panelid_id, data[0]);
    setFieldValue(record, panelname_id, data[1]);
    // Continue for other fields…
    return record;
    }
    `
    – **Parameterization**: Consider passing parameters to functions rather than relying on global variables. This makes the functions more reusable.

    ### 3. **Configuration and Flexibility**:
    – **Configurable Field Mappings**: Instead of hardcoding the field IDs, store them in a configuration object. This allows for easier updates and the possibility of reusing the script with different forms.
    `javascript
    const fieldMappings = {
    panelid: ‘fld-36efa15d8bd6410b8fe7f19d6e0b53bd’,
    panelname: ‘fld-2b9958a1f5e145fe929993d960ca2bd2’,
    // Add other mappings here…
    };
    `
    – **Dynamic File Path**: Use a file picker dialog to select the CSV file dynamically, making the script more flexible and user-friendly.
    `javascript
    let filename = Utils.getFilePathFromDialog();
    if (!filename) {
    console.log(“No file selected.”);
    return;
    }
    `

    ### 4. **Progress Indicator Enhancements**:
    – **More Informative Progress**: Instead of just updating the progress indicator, display which record is currently being processed, especially useful for large imports.
    `javascript
    progress.show(Importing Data... (${index + 1}/${output.data.length}));
    `

    ### 5. **Improving Efficiency**:
    – **Batch Record Updates**: If Tap Forms supports it, consider updating records in batches rather than one at a time. This could improve performance, especially with large datasets.
    – **Early Exit on Cancel**: The script currently checks progress.cancelled in the loop. Consider exiting the loop immediately if the operation is canceled to save processing time.

    ### 6. **User Feedback**:
    – **User Confirmation Before Deletion**: Ask for user confirmation before deleting all records, to prevent accidental data loss.
    `javascript
    if (!Utils.confirmWithMessage(“Are you sure you want to delete all records?”, “Confirmation”)) {
    return;
    }
    `
    – **Detailed Completion Message**: Include the number of records processed in the completion message.
    `javascript
    Utils.alertWithMessage(“Import Successful”, The data delete & import has been completed successfully. ${output.data.length} records processed., “info”);
    `

    ### 7. **Documentation and Comments**:
    – **Add Comments**: Enhance the script with detailed comments explaining each section of the code, which will be helpful for anyone who needs to maintain or update the script in the future.
    `javascript
    // Parse date in dd/mm/yyyy format to JavaScript Date object
    function parseDate(dateString) {
    if (!dateString) {
    return undefined;
    }
    let pieces = dateString.split(“/”);
    return new Date(pieces[2], pieces[1] – 1, pieces[0]);
    }
    `

    Implementing these improvements can make the script more robust, flexible, and easier to maintain, providing a better user experience while reducing the likelihood of errors.

    #51056
    David Oxtoby
    Participant

    Having the save all changes outside of the loop commits all of the changes at once and makes it more efficient. Inside the loop slows things down because it commits everything for each row. There is also a progress bar control you can use to communicate where you’re at with things which is useful for an import style use case like this.

    Thx for the idea, I found some posts about the progress bar and have now implemented also, I’ll include full code below in case helpful for others searching….

     

    // Import the Papa Parse script
    form.runScriptNamed(‘PapaParse’);
    // Replace with field IDs
    var panelid_id = ‘fld-36efa15d8bd6410b8fe7f19d6e0b53bd’;
    var panelname_id = ‘fld-2b9958a1f5e145fe929993d960ca2bd2’;
    var paneldate_id = ‘fld-1c958e3560f54bb4a2069679437ffff2’;
    var paneltime_id = ‘fld-5b8a1a7f74884f2c8889cf2e607b93ab’;
    var paneltype_id = ‘fld-94a01f8bac044807a92665787ce31e84’;
    var forenames_id = ‘fld-a7a75f6b28734d79a1b9f9f7dfd9b62e’;
    var surname_id = ‘fld-761d46b9635a47c691077c0e421babe2’;
    var email_id = ‘fld-39b7278d93a140738bd4d43c398200af’;
    var attendeetype_id = ‘fld-3243fd4febb8442388b94ef448d51cdb’;
    var diocesename_id = ‘fld-59d821b7348046fa8558a88a2eb0e04f’;
    var portalref_id = ‘fld-3f7992d2c715418eb4876742c0f42cac’;
    var hometel_id = ‘fld-16675cd8390a4360beb8f48a8a61cf63’;
    var worktel_id = ‘fld-200cc33874da4a2caa022b245f94c874’;
    var panelid2_id = ‘fld-9aef36638f2d47918ba8e4ef0ebf02d5’;
    var sponsoredministry_id = ‘fld-07fe8cc64e2d49e1907358d1412676c7’;
    var uniquefield_id = ‘fld-e10dc8a981164a689c1396432fe827fe’;
    var season_id = ‘fld-7e019716a16a439786b5f18f4ee77e90’;
    var p_lay_id = ‘fld-f33a9860109c4e2a9e337413de2f436f’;
    var p_ordained_id = ‘fld-0a3fd09705a849148741e7375be67ca9’;
    var mfaorpfa_id = ‘fld-6eb4defe3b0943f1ba84526dece268c4’;
    var mp1or2_id = ‘fld-3cd37ee306234fc7b9fd924327889849’;
    var attendeeteam_id = ‘fld-086d714f95884357b0fbcf214abb316c’;
    var teamkey_id = ‘fld-800f79fc21f84ec0ac978053afe829ed’;
    var name_id = ‘fld-14547469b33f4620b2196218dd29e322’;
    var carousel_id = ‘fld-c97e4fc2aaac4d16a1d43dd1bf41f16d’;
    var panel_id = ‘fld-f595e901f0cd4a7fbc8d6a752f048c78’;
    var portalid_id = ‘fld-c1fc7ac3bf8e49be8a483d90bb1942a7’;
    var panelsecsurname_id = ‘fld-fef1fa3cae61404384647ec54c9dd6a4’;
    // Function to delete all records
    function deleteAllRecords(){
    for (rec of form.getRecords()){
    form.deleteRecord(rec);
    }
    document.saveAllChanges();
    }
    // Function to split date and parse it
    function parseDate(dateString) {
    if (!dateString) {
    return undefined;
    }
    let pieces = dateString.split(“/”);
    return new Date(pieces[2], pieces[1] – 1, pieces[0]);
    }
    // Function to parse time in the format hh:mm
    function parseTime(timeString) {
    if (!timeString) {
    return undefined;
    }
    let pieces = timeString.split(“:”);
    let date = new Date();
    date.setHours(pieces[0], pieces[1], 0, 0);
    return date;
    }
    // Function to import entries
    function Import_Entries() {
    let filename = “file:///Users/davidoxtoby/Library/CloudStorage/OneDrive-ChurchofEnglandCentralServices/Documents/In progress/Reports/qryPanelData (TapForms).csv”;
    let csvFile = Utils.getTextFromUrl(filename);
    if (!csvFile) {
    console.log(“No CSV file?”);
    return;
    }
    var output = Papa.parse(csvFile);
    // Abort if there are any errors and log to console.
    if (output.errors.length > 0) {
    console.log(output.errors.join(“\n”));
    return;
    }
    // Initialize progress indicator
    var progress = Progress.new();
    progress.totalCount = output.data.length;
    progress.currentCount = 1;
    progress.show(‘Importing Data…’);
    // Read each line
    for (let index in output.data) {
    let line = output.data[index];
    if (progress.cancelled) {
    console.log(‘Cancelled operation’);
    break;
    }
    // Date and time parsing
    let paneldate_new = parseDate(line[2]);
    let paneltime_new = parseTime(line[3]);
    var newRecord = form.addNewRecord();
    newRecord.setFieldValues({
    [panelid_id]: line[0],
    [panelname_id]: line[1],
    [paneldate_id]: paneldate_new,
    [paneltime_id]: paneltime_new,
    [paneltype_id]: line[4],
    [forenames_id]: line[5],
    [surname_id]: line[6],
    [email_id]: line[7],
    [attendeetype_id]: line[8],
    [diocesename_id]: line[9],
    [portalref_id]: line[10],
    [hometel_id]: line[11],
    [worktel_id]: line[12],
    [panelid2_id]: line[13],
    [sponsoredministry_id]: line[14],
    [uniquefield_id]: line[15],
    [season_id]: line[16],
    [p_lay_id]: line[17],
    [p_ordained_id]: line[18],
    [mfaorpfa_id]: line[19],
    [mp1or2_id]: line[20],
    [attendeeteam_id]: line[21],
    [teamkey_id]: line[22],
    [name_id]: line[23],
    [carousel_id]: line[24],
    [panel_id]: line[25],
    [portalid_id]: line[26],
    [panelsecsurname_id]: line[27]
    });
    // Update the progress indicator
    progress.updateProgress(index);
    }
    // Dismiss the progress indicator
    progress.dismissProgress();
    // Save changes
    document.saveAllChanges();
    Utils.alertWithMessage(“Import Successful”, “The data delete & import has been completed successfully.”, “info”);
    }
    // Delete all records before importing
    deleteAllRecords();
    // Start the import process
    Import_Entries();
    #51046
    David Oxtoby
    Participant

    I’ve got the following script doing what I hoped, i.e. importing from a CSV file, however…. once it looks like the script has run (i.e. i can see record numbers increasing) TapForms just hangs using 99% CPU, and only thing I can do is force quit.  When I re-open the records look ok, so not sure what’s causing the hang, any pointers/ideas anyone?

     

    // this imports the Papa Parse script
    form.runScriptNamed(‘PapaParse’);
    // replace with your field ID’s
    var panelid_id = ‘fld-36efa15d8bd6410b8fe7f19d6e0b53bd’;
    var panelname_id = ‘fld-2b9958a1f5e145fe929993d960ca2bd2’;
    var paneldate_id = ‘fld-1c958e3560f54bb4a2069679437ffff2’;
    var paneltime_id = ‘fld-5b8a1a7f74884f2c8889cf2e607b93ab’;
    var paneltype_id = ‘fld-94a01f8bac044807a92665787ce31e84’;
    var forenames_id = ‘fld-a7a75f6b28734d79a1b9f9f7dfd9b62e’;
    var surname_id = ‘fld-761d46b9635a47c691077c0e421babe2’;
    var email_id = ‘fld-39b7278d93a140738bd4d43c398200af’;
    var attendeetype_id = ‘fld-3243fd4febb8442388b94ef448d51cdb’;
    var diocesename_id = ‘fld-59d821b7348046fa8558a88a2eb0e04f’;
    var portalref_id = ‘fld-3f7992d2c715418eb4876742c0f42cac’;
    var hometel_id = ‘fld-16675cd8390a4360beb8f48a8a61cf63’;
    var worktel_id = ‘fld-200cc33874da4a2caa022b245f94c874’;
    var panelid2_id = ‘fld-9aef36638f2d47918ba8e4ef0ebf02d5’;
    var sponsoredministry_id = ‘fld-07fe8cc64e2d49e1907358d1412676c7’;
    var uniquefield_id = ‘fld-e10dc8a981164a689c1396432fe827fe’;
    var season_id = ‘fld-7e019716a16a439786b5f18f4ee77e90’;
    var p_lay_id = ‘fld-f33a9860109c4e2a9e337413de2f436f’;
    var p_ordained_id = ‘fld-0a3fd09705a849148741e7375be67ca9’;
    var mfaorpfa_id = ‘fld-6eb4defe3b0943f1ba84526dece268c4’;
    var mp1or2_id = ‘fld-3cd37ee306234fc7b9fd924327889849’;
    var attendeeteam_id = ‘fld-086d714f95884357b0fbcf214abb316c’;
    var teamkey_id = ‘fld-800f79fc21f84ec0ac978053afe829ed’;
    var name_id = ‘fld-14547469b33f4620b2196218dd29e322’;
    var carousel_id = ‘fld-c97e4fc2aaac4d16a1d43dd1bf41f16d’;
    var panel_id = ‘fld-f595e901f0cd4a7fbc8d6a752f048c78’;
    var portalid_id = ‘fld-c1fc7ac3bf8e49be8a483d90bb1942a7’;
    var panelsecsurname_id = ‘fld-fef1fa3cae61404384647ec54c9dd6a4’;
    // Function to split date and ressemble (to be called later)
    function parseDate(dateString) {
    if (!dateString) {
    return undefined;
    }
    let pieces = dateString.split(“/”);
    return new Date(pieces[2], pieces[1] – 1, pieces[0]);
    }
    function Import_Entries() {
    let filename = “file:///Users/davidoxtoby/Library/CloudStorage/OneDrive-ChurchofEnglandCentralServices/Documents/In progress/Reports/qryPanelData (TapForms).csv”;
    let csvFile = Utils.getTextFromUrl(filename);
    if (!csvFile) {
    console.log(“No CSV file?”);
    return
    }
    var output = Papa.parse(csvFile);
    // abort if there are any errors and log to console.
    if (output.errors.length > 0) {
    console.log(errors.join(“\n”));
    return;
    }
    // read each line
    for (let line of output.data) {
    // date of event parsing
    let paneldate_id_string = line[2];
    let paneldate_new = parseDate(paneldate_id_string);
    var newRecord = form.addNewRecord();
    newRecord.setFieldValues({
    [panelid_id]: line[0],
    [panelname_id]: line[1],
    [paneldate_id]: paneldate_new,
    [paneltime_id]: line[3],
    [paneltype_id]: line[4],
    [forenames_id]: line[5],
    [surname_id]: line[6],
    [email_id]: line[7],
    [attendeetype_id]: line[8],
    [diocesename_id]: line[9],
    [portalref_id]: line[10],
    [hometel_id]: line[11],
    [worktel_id]: line[12],
    [panelid2_id]: line[13],
    [sponsoredministry_id]: line[14],
    [uniquefield_id]: line[15],
    [season_id]: line[16],
    [p_lay_id]: line[17],
    [p_ordained_id]: line[18],
    [mfaorpfa_id]: line[19],
    [mp1or2_id]: line[20],
    [attendeeteam_id]: line[21],
    [teamkey_id]: line[22],
    [name_id]: line[23],
    [carousel_id]: line[24],
    [panel_id]: line[25],
    [portalid_id]: line[26],
    [panelsecsurname_id]: line[27]
    });
    document.saveAllChanges();
    }
    }
    Import_Entries();
    #51044
    Brendan
    Keymaster

    Hi David,

    You can import data from a file into Tap Forms. But you’re responsible for parsing the data and assigning it to fields yourself.

    var product_info = Utils.getTextFromUrl(url);

    You could use a local URL such as file:///Users/username/Desktop/products.csv

    You need to set the Script Folder access setting on the General Settings screen to a folder you want to read the file from.

    But it’s certainly possible.

    Thanks,

    Brendan

    #51043
    David Oxtoby
    Participant

    Thank you, that works a treat.

    Can Importing being scripted do we know?

     

    Thx

    #51042
    Daniel Leu
    Participant

    This script will delete all records in the current form. So that’s a bit dangerous! Use with care!

    function deleteAllRecords(){
    
    for (rec of form.getRecords()){
    
    form.deleteRecord(rec);
    
    }
    
    document.saveAllChanges();
    
    }
    
    deleteAllRecords();
    
    

    Cheers, Daniel

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

    #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, 2 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, 2 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, 2 months ago by tapforms_user. Reason: Added script in text file attachment
    • This topic was modified 1 year, 2 months ago by tapforms_user.
    • This topic was modified 1 year, 2 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.

Viewing 15 results - 286 through 300 (of 2,950 total)