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 - 496 through 510 (of 2,989 total)
  • Author
    Search Results
  • #49880

    In reply to: Convert 2 fields

    Brendan
    Keymaster

    Well, instead of the Script field actually returning a value, you can just have it set the value on the field, depending on what field you entered data into. The script will execute when you change a value in a field that’s reference in the getFieldValue() function. You can even hide the Script field from your form and it will still execute when the fields you reference are updated.

    #49878

    In reply to: Convert 2 fields

    Glen Forister
    Participant

    OK, that does make it work.  I see now that those were parameters, so a comma was needed.

    Thanks.

    I assume though, that making it work both ways, with some records getting the value of ft to be converted to meters, and other records being given the Meters to be converted to Ft. would not work because apparently one has to be a number field and the other has to be a Script field.

    Is that correct?  It would be nice if the calc went both ways because I sometimes know one value and other times I know the other.

    #49861
    Brian Lennon
    Participant

    I fixed the ID to Id thingy and the script seems to run start to finish producing URLs (that I don’t understand yet).  BUT, there is no copying of records from the source form to the target form.  Is there something I’m missing?

    My target form is a duplicate of the source form.

    (Very much a beginner with Javascript but making progress thanks to Sam’s videos!)

    #49850
    Brian Lennon
    Participant

    I have been very impressed with how easy it was to import several thousand records from a previous database into Tap Forms 5. Adding pick lists, calculation fields and the like worked so well. There is one aspect I need advice on.

    The way I previously stored records of training completed by each person is one I need to change. (The previous TRAINING records only carried a course code and a person code.) So far I have managed to write a script that extracts the course codes for each person from a one-to-one linked field (“TRAINING”). Now what I want to do it insert these codes (“course_code”) into another many-to-many linked field (“TRAININGnew”) and I don’t know how to script this.

    Manually it works. I go to TRAININGnew, click on the little tick at the bottom that prompts “Select existing linked records”, I click on the course code from the linked form COURSES and the relevant course code and details appear in TRAININGnew. I need the script equivalent of this action. So my question is, how do I script this so that it will use the course_code extracted from TRAINING and select an existing course record identified by this course code in the TRAININGnew link so that the full course details will appear in the TRAININGnew link.

    Many thanks

    Brian Lennon

    #49849

    In reply to: Convert 2 fields

    Glen Forister
    Participant

    Ok, my Ft filed is a Number record.
    My meter filed is a Script field.

    It doesn’t do anything.  At least there isn’t a error.  I’m not checking the field for being empty because that is beyond me.  Trying to do one step at a time.  (in a test bed Form).

    This is the code.

    
    
    function Meter() {
    
    // Get the current record
    
    // Replace "sourceField" and "targetField" with the actual field names in your form
    var ft_id = 'fld-50c724b718da4b6dbcb64556bcec55d9';
    var sourceValue = record.getFieldValue(ft_id);
    
    // Perform the conversion (e.g., convert from inches to centimeters)
    var conversionFactor = 2.54; // 1 foot = 0.3048 meters;
    var targetValue = sourceValue * conversionFactor;
    
    // Update the "targetField" with the result
    var meter_id = 'fld-21efc0b907ac4d14871fcb9cccb22e2b';
    var FieldValue = record.getFieldValue(meter_id);
    
    // Save the record to apply the changes
    form.saveAllChanges() ;
    
    }
    
    Meter();
    
    
    #49848

    In reply to: Convert 2 fields

    Brendan
    Keymaster

    You will need to check to see if the target field is empty or not before doing the conversion. And it will be executed every time you make a change as long as this code is a Field script and not a Form script. A Field script is one that’s added as a regular field to your form, but can contain script code. A Form script is one you add to the Scripts tab on the Form inspector panel.

    #49829

    Topic: Convert 2 fields

    in forum Script Talk
    Glen Forister
    Participant

    I have 2 fields “feet” and “meters” which relate to the elevation of a location of a record.

    I often have feet, or meters but not both.  I want a script (I assume to put in the “Script” tab of that form to check if a record has one of the fields not empty, then to convert to the other field.  If both fields are not empty, leave it alone.

    I asked ChatGPT and it gave me this to do a simple conversion to see if I could get started and I pasted in between the Function Names.

    My first stumble was I couldn’t find the command in the directory of Script commands in the first statement  “form.getSelectedRecords()[0]”.  Do I insert something in the ()?  I asked in the other forum, but couldn’t get any script help there.  I think I understand how to put in the “sourceField” and the “targetField”.

    function Convert_Elev() {

    // Get the current record
    var record = form.getSelectedRecords()[0];

    // Replace “sourceField” and “targetField” with the actual field names in your form
    var sourceValue = record.getFieldValue(“sourceField”);

    // Perform the conversion (e.g., convert from inches to centimeters)
    var conversionFactor = 2.54; // 1 foot = 0.3048 meters
    var targetValue = sourceValue * conversionFactor;

    // Update the “targetField” with the result
    record.setFieldValue(“targetField”, targetValue);

    // Save the record to apply the changes
    record.save();

    }

    Convert_Elev();

    Convert_Elev() {

    // Get the current record
    var record = form.getSelectedRecords()[0];

    // Replace “sourceField” and “targetField” with the actual field names in your form
    var sourceValue = record.getFieldValue(“sourceField”);

    // Perform the conversion (e.g., convert from inches to centimeters)
    var conversionFactor = 2.54; // 1 foot = 0.3048 meters
    var targetValue = sourceValue * conversionFactor;

    // Update the “targetField” with the result
    record.setFieldValue(“targetField”, targetValue);

    // Save the record to apply the changes
    record.save();

    }

    Convert_Elev();

    #49827
    Glen Forister
    Participant

    I want to test a script, but not in my original form.

    How do I make a copy of my form with just a few or all of the records so I can test something?

    I’ve tried saving an archive of the form and changing the name on it and importing it, but it just disappears – were the empty records imported into the current form from which it came???

    I’ve tried making a copy of the form, but that form is empty.  How do I get some data into the copy form without making up stupid data with a lot of work?

    What is the best procedure here?

    #49821

    In reply to: conversions

    Glen Forister
    Participant

    I’ve tried to learn, but just can’t spend enough time to remember enough.  Went through quite a bit of a javascript course, but then time got short and I started forgetting stuff.

    If this was a little bit more straight forward, I would try ChatGPT.  I’ve asked it to program some things and I’m amazed at the results.

    The other concern is since I already have 70 records all filled in I don’t want to lose that data, so I have to build in a double if clause that if both fields are filled not to do anything (I guess that would be my first If clause in which all else would occur.

    Some Script help here would be greatly appreciated.

    Thanks.

    #49820

    In reply to: conversions

    Brendan
    Keymaster

    Hi Glen,

    You would need to use a Script field for this. In your Script field you’ll need to get the value of each field. Then do your conversion, then set the value in the other field. Just check to make sure you set the value on the field if it’s empty.

    https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api

    Have you done any scripting in Tap Forms before?

    Thanks,

    Brendan

    #49815
    Pinny Berlin
    Participant

    Hi,

    I have a neat POI form that tracks all of my favorite destinations and uses JavaScript to calculate their distance from my current location. (It sorts by Distance, making it easy to see which places are nearby.)

    I created a POI record called Current Location which I manually update each time I travel. Each other POI calculates the distance away from that Current Location POI.

    I was wondering if there is anyway to automatically update the Location field of my Current Location record. I have googled a bit and see mention of a navigator.geolocation object, but Tapforms throws an error when I try to reference it.

    Does anyone have any other ideas how I might capture my Current Location via JavaScript?

     

    Thanks,

    Pinny

    • This topic was modified 2 years, 4 months ago by Pinny Berlin. Reason: Added photo of Form
    Attachments:
    You must be logged in to view attached files.
    #49811

    In reply to: Setting Current Date

    John Juhl
    Participant

    Hi Brendan,

    thanks for your reply – I don’t recall at the moment what I tried, but from what I can read out of your Script I did get the check-field syntax wrong, since I worked with true/false instead of 0/1.

    It’s a bit late here in Denmark right now, but I’ll have a play with your script first thing in the morning.

     

    Thanks,

    John.

     

    #49802

    In reply to: Setting Current Date

    Brendan
    Keymaster

    Hi John,

    What script have you written to do this?

    Something like this should work:

    function setCurrentDate() {
    var check_field_id = "fld-.....";
    var date_field_id = "fld-....";
    var check_value = record.getFieldValue(check_field_id);
    if (check_value == 1) {
    record.setFieldValue(date_field_id, new Date());
    }
    form.saveAllChanges();
    
    }
    
    setCurrentDate();
    • This reply was modified 2 years, 4 months ago by Brendan.
    • This reply was modified 2 years, 4 months ago by Brendan.
    #49800
    John Juhl
    Participant

    Hi guys,

    I’m trying to figure out how to make this work:

    • I have a CheckMark field
    • and would like to make value in a Date field change
    • when the CheckMark field is Checked

    I’ve tried different Script Approaches, with no luck so far

    How would I do this?

     

    kr.

    John

    #49794
    Daniel Leu
    Participant

    In one of my forms, I encountered an issue of  missing parents. The contact field should contain the infos from the parent. This form script loops over all records of a form and checks if the contact field contains records. If no record is found (eg, length == 0), I set the select field. Afterwards, I can use a smart filter to find all these records where the select field is set to 1. This way, I can verify that these records are indeed the once I want to delete. Maybe this helps you!

    function Select_No_Contact_Parent() {
    
       const contact_id = 'fld-xxx';
       const select_id = 'fld-xxx';
       for (rec of form.getRecords()){
         let contacts = rec.getFieldValue(contact_id);
          if (contacts.length == 0) {
           rec.setFieldValue(select_id, true);
          }
       }
       document.saveAllChanges();
    }
    Select_No_Contact_Parent();
    • This reply was modified 2 years, 5 months ago by Daniel Leu.
    • This reply was modified 2 years, 5 months ago by Daniel Leu.
    • This reply was modified 2 years, 5 months ago by Daniel Leu.

    Cheers, Daniel

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

Viewing 15 results - 496 through 510 (of 2,989 total)