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 - 931 through 945 (of 3,053 total)
  • Author
    Search Results
  • David Schwane
    Participant

    I have this script that returns a random record regardless if I’m on a form or a saved search. Works great but I know using try catch this way is not correct. What is a better way to resolve if I’m trying to get a form recordset or search recordset?

    Random_Record();
    try {
    var records = search.getRecords();
    }
    catch (err) {
    var records = form.getRecords();
    }
    var record = records[Math.floor(Math.random() * records.length)];
    form.selectRecord(record);

    #47411
    Brent Willingham
    Participant

    Thanks for the script Brendan. Glad to know about the new feature for a future release. If I can get this working, my goal is to share it with other land managers and ranchers in Texas for them to use. We all have to submit a report to the County at the end of each year and it can be a pain going through receipts and trying to remember everything. This could help keep things organized.

    #47409
    Brendan
    Keymaster

    Here’s the form template. The only problem with it is if you switch records, the Province pick list would not be synced with the Country selection until you actually changed the country.

    FYI, I have already built a new cascade pick list feature into the next big version of Tap Forms I’m currently working on. No ETA though. And no scripting required for it.

    Attachments:
    You must be logged in to view attached files.
    #47408
    Brendan
    Keymaster

    Here’s a script that I was messing around with that will change the Province field’s Pick List depending on the value selected from the Country field’s Pick List:

    function Province_Pick_List_Switcher() {
    
    	var country_id = 'fld-de7985c881804154b037c68dc4c24414';
    	var country = record.getFieldValue(country_id);
    	var canadian_provinces_pick_list = document.getPickListNamed('Canadian Provinces');
    	var us_states_pick_list = document.getPickListNamed('US States');
    	var province_id = 'fld-b1458c16690744129ff145f7b9607c99';
    	var province = form.getFieldWithId(province_id);
    	
    	if (country == 'Canada') {
    		province.pickList = canadian_provinces_pick_list;
    		
    	} else if (country == 'United States') {
    		province.pickList = us_states_pick_list;
    		
    	} else {
    		province.pickList = null;
    	}
    	
    }
    
    Province_Pick_List_Switcher();

    You could modify this script for your own needs. I added it as a Script Field and then hid the Script Field so it doesn’t show on the form, but it still works.

    #47407
    Brent Willingham
    Participant

    Ok, I’ve created a new database called Wildlife Exemption and a form called Wildlife. I’ve created all my fields, one of which is a Pick List field called “Management Practice”. I created a corresponding pick list also named “Management Practice”. There are 7 values in the “Management Practice” pick list. One of the values is “Habitat Control”.

    I have created pick lists for each of those 7 values that I am referring to as “sub practices”. So, for example, I have a pick list called “Habitat Sub Practice”. In that pick list are things like Grazing Management and Brush Management.

    The idea is that when the user is on the “Management Practice” field, they are presented with the list from the “Management Practice” pick list. They have 7 options, but let’s say the choose “Habitat Control”. The next field on the form is called “Sub Practice”. In this field, the pick list “Habitat Sub Practice” would be chosen because of the selection above.

    The only way I can think of to do this is with a long nested IF THEN kind of routine:
    IF Management Practice = “Habitat Control” THEN “Habitat Sub Practice”
    ElSE IF Management Practice “Erosion Control” THEN “Erosion Sub Practice”
    and do 5 more ELSE IF’s so that all 7 Management Practice options are covered.

    I’m guessing that this is probably not the smartest way to go about it, and I’m sure I have the syntax way off. I’ve gone through T.L. Ford’s Java Scripting 101 and that has been very helpful, but my only programming experience is with BASIC decades ago in High School.

    Would someone be able to get me kicked off with the start of a script here?

    Thanks,
    Brent

    #47404

    In reply to: Tap Forms Form Hooks

    Bernie McGuire
    Participant

    Brendan Hi Ok Ill think about this. I guess there is no problem to insert a Record in a different form than the form with the field script, correct ? Ill give it a try and post here the results.
    Bernie

    #47403

    In reply to: Tap Forms Form Hooks

    Brendan
    Keymaster

    Field scripts execute whenever a value they’re monitoring changes. So if you’re entering data anyway, you could monitor for that change and insert the records you want at that point. You don’t even have to be doing anything with the field you’re monitoring. Just to know that it has changed and the script will be triggered. But no script will get triggered just by viewing a record.

    #47401

    In reply to: Tap Forms Form Hooks

    Bernie McGuire
    Participant

    Brendan Hi thanks for the opportunity to explain. I will try to be brief but somewhat detailed.
    I have 3 linked forms
    1. Drill Description
    2. Drill Results (One record for each time a drill is executed)
    3. Drill Total Results (One Record for each Drill with accumilated totals of rows in number 2 above. Totals are calculated using Calculation of linked fields

    One time process : Load a description for all possible drills in Form 1 assign a ‘DrillID”

    Eacb time a drill is executed :
    1. Open form 1, drill description
    2. Pick a drill and click on the + next to linked Form Drill Results (2)
    3. Enter Results and either pick a new Drill Description or exit

    The Problem as I see it. The records in table 3 (Drill Total Results) need to be manually added the first time a drill has results which for me, is extra work on the user part I like to avoid. As if the user forgets to pen the Form and add a row, no totals will ever be displayed.

    What I have done is write a script that will look at all the records in table 2 (Results) and check if a Record exists (by Drill ID) in Table 3 (Totals), if exists, do nothing, if not exists add new row. Now when a Drill Description is open the linked forms for both Results and Totals will be present and viewable.
    This script has to be executed manually using the Form Run Script command. It would be nice if it could be executed ‘ON Open’ automatically.
    Or is there another way to accomplish script execution without user intervention?

    Hope this is clear.
    Thanks for the help
    Bernie

    Michael Tucker
    Participant

    These MOASS Ladder templates have gotten some revisions..

    (1) Mainly I had forgotten to connect the fractional shares field, and when corrected that blew three scripts, all revised.

    (2) Then also I have added a way to re-use the Goal Section within multiple Ladders. Usually your goal list would remain static.

    New versions below.

    #47391
    Bernie McGuire
    Participant

    Are there any available hooks in a Form such as ‘ON Open” o ‘On Close’ etc. Where one could have a script execute based on this event?
    Thanks

    #47371
    Brendan
    Keymaster

    Hi David,

    You can do this with a Calculation field, but it would be much easier to understand with a Script field.

    Just off the top of my head without actually testing it out, here’s a script that “should” work:

    function getResult() {
       let margin_id = 'fld-....';
       let money_id = 'fld-....';
       let margin = record.getFieldValue(margin_id);
       let money = record.getFieldValue(money_id);
       var result = 0;
    
       if (margin < 25)
          result = 0;
       } else if (margin >= 25 || margin <= 27) {
          result = money * 0.08;
       } else if (margin > 27 || margin <= 30) {
          result = money * 0.1;
       } else {
          // not sure what happens if margin is greater than 30?
       } 
     
       return result;
    
    }
    
    getResult();

    So add a Field Script and copy this code into your script and then change the field IDs appropriately to match the actual field IDs of your own Margin and Money fields.

    It should work.

    Thanks,

    Brendan

    #47370
    David Figge
    Participant

    Ok, I am trying to learn some scripting for the calc field but I am running out of time in my evaluation process of TF (which so far has been amazing) and we have a use case that we can do in Numbers but unsure if we can in TF.

    I am trying to do an if/then usineg two fields. One is a Margin field (which is a number field) and the other is a money field. Basically I am trying to get a final calculation from certain numbers. It looks like this

    I the (Margin) is <25 then 0
    If the (Margin) is > or equal to 25-27 then (Money) * .08
    If the (Margin) is > or equal to 27-30 then (Money) * .10

    Is this possible in the calculation field and if so…If someone would be willing to show me how it will help a ton with me starting to understand exactly how this scripting works.

    #47326

    In reply to: Help with a script 3

    Brendan
    Keymaster

    Oh, it’s just a matter of the wrong field IDs in the script. I guess I used an archive of the form you sent me a while ago to write the script. You also renamed the Kalvningar field to Antal kalvningar so that took me a minute to find it again.

    var kalvningar_id = 'fld-cdb4431a905f4b1dbaa750b07a63b6f1';

    When you see an error in the console, first check to make sure all the field IDs in the code match the field IDs on the left. You can select a field and see its ID below.

    #47317

    In reply to: Help with a script 3

    Daniel Leu
    Participant

    Hi Stig, instead of sharing a TapForms template, could you share a TapForms archive of a document that contains entries for just a few animals? I tried to see what the script does, but it returns an error. I don’t know if I missed to enter some data or if there is an issue with the script. Having a TapForms archive with known data would make debugging much easier. Thanks!

    Cheers

    Cheers, Daniel

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

    #47315

    In reply to: Help with a script 3

    Stig Widell
    Participant

    Thank you Brendan for your efforts.
    Unfortunately I have to bother you once more because nothing shows up in the added script fields.
    Regards
    Stig

    Attachments:
    You must be logged in to view attached files.
Viewing 15 results - 931 through 945 (of 3,053 total)