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 - 646 through 660 (of 2,951 total)
  • Author
    Search Results
  • #48666

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    I figured that out. thanks.
    The file I used was for learning and had only this season. I thought it would be good to start with a small file.
    I tried to import the whole 5 years into the file, but import created a new file Form with the same name instead of adding to the current form. So I tried to duplicate the format for the new form but failed. I think I have all the file properties correct, but the script just gives me “NaN” in the field (even after repeated refresh). You have a clue what I missed, or can I copy records from this form and add them to the working form?

    BTW, somehow the Date col disappeared which produced bogus charts obviously. I added a new Field (DATE) and moved it to the top and after configuring the field the original data appeared out of nowhere. What happened here? I couldn’t find that data until it suddenly appeared, and how did it disappear in the first place?

    #48657

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    That didn’t quite work. Looping to get all every time? Here is the first 3 lines of the relult. This is one thing I like about programming, always a surprise.
    Day tot. Sum
    0.03 0
    0.31 0.310
    0.23 0.230.310
    0.33 0.330.230.310

    Brandon’s script results
    0.03 0
    0.31 0.310
    0.23 0.230.310
    0.33 0.330.230.310

    • This reply was modified 2 years, 10 months ago by Glen Forister.
    #48655

    In reply to: Learning JavaScript

    Daniel Leu
    Participant

    Sorry, this is intended to be a field script for the Season Tot field.

    And you need to run Refresh Records List (control-option R).

    • This reply was modified 2 years, 10 months ago by Daniel Leu.

    Cheers, Daniel

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

    #48654

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    That loop script doesn’t do anything either.

    #48652

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    I’m recording daily rain fall (morning, noon and night)I want each record to show the total for that day (done) and add that to the previous season total to get the new season total.
    each record has the total for the day and the season total

    I added the Script to the list of Scripts, then noticed the change of field properties to Script instead of Calculated and put the script there, but nothing happened.

    Am I supposed to change the script to enter the field somewhere?

    Why a loop?

    • This reply was modified 2 years, 10 months ago by Glen Forister.
    #48651

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    I’m recording daily rain fall (morning, noon and night)I want each record to show the total for that day (done) and add that to the previous season total to get the new season total.
    each record has the total for the day and the season total

    I added the Script to the list of Scripts, then noticed the change of field properties to Script instead of Calculated and put the script there, but nothing happened.

    Am I supposed to change the script to enter the field somewhere?

    #48650

    In reply to: Learning JavaScript

    Brendan
    Keymaster

    Thanks for posting your script Daniel. I had a couple syntax errors in mine which I updated to fix.

    I wonder if Glen wants a cumulative total and not just a total from the previous and today’s totals? If that’s the case, then maybe a Form level script to loop through all the records and update a cumulative total field would be required?

    #48648

    In reply to: Learning JavaScript

    Daniel Leu
    Participant

    Hi Glen,

    Thank you for sharing your form! The script Brendan posted is for a field of the type Script and not Calculation.

    Here is the updated script that works for me:

    function Season_to_date() {
    	
    	var records = form.getRecords();
        	var currentRecordIndex = records.indexOf(record);
    
        	if (currentRecordIndex > 0) {
            	var previousRecord = records[currentRecordIndex-1];
        	} else {
         		return 0;
        	}
    
    	var today = record.getFieldValue('fld-61c03b767f2c497491d10a28db8abdb3');
    	var previous_total = previousRecord.getFieldValue('fld-f6bc7e82da874579940fb8afc167dac4');
    	var total = today + previous_total;
    	
    	console.log("Today: " + today)
    	console.log("Previous: " + previous_total)
    	console.log("Total: " + total)
    	
    	return total;
    }
    
    Season_to_date();

    Cheers, Daniel

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

    #48646

    In reply to: Learning JavaScript

    Brendan
    Keymaster

    Hi Glen,

    You put that script code into a Calculation field.

    You need to put it into a Script field, not a Calculation field.

    #48644

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    Thanks for the script, but it doesn’t do anything, I suppose be cause I have to define where to get the previous record and then add today’s total to it. I could probably spend the rest of the day working on this and not figure it out I’m sure.

    I’ve attached my file and maybe if you fix it I can apply the example to other similar forms I have to import data for.
    Thanks.

    Attachments:
    You must be logged in to view attached files.
    #48637
    Mike Guilbault
    Participant

    I’m trying to extract the phone number from a linked form.
    The current form is called Appointments and the field is simply called “Phone”
    The linked form is called “INSTALLS” and the field I want to draw from is called “Best Phone”

    This is the error I get when I run the script:
    2023-01-13, 8:27:29 PM / Appointments / Phone
    Phone: SyntaxError: Invalid character ‘\u2018’, line:3

    and this is the Script:

    function Phone_Script() {
    
    	var Phone_id = ‘’fld-1a146d1f63aa43c0881af16b1e65f1be;
    	var Best_Phone = record.getFieldValue('fld-eef8580ecdb744bf94a58eb1b7997a89');
    	if (Best_Phone != undefined) {
    		var Phone = Best_Phone.getFieldValue(Phone_id);
    	
    		return Phone;
    	} else {
    		return "";
    	}
    }
    
    Phone_Script();

    Any suggestions?

    • This topic was modified 2 years, 10 months ago by Brendan.
    #48636

    In reply to: Learning JavaScript

    Brendan
    Keymaster

    There’s no function in the Calculation field to reference the previous record. Calculations work only on the current record.

    You would probably have to use JavaScript to do that. But then, what really is the previous record? It really depends on how you sort your records.

    #48630

    In reply to: Learning JavaScript

    Brendan
    Keymaster

    Hi Glen,

    Instead of JavaScript, you could also just use a Calculation field.

    In your previous JavaScript question, the solution to get the difference between two dates in months is this formula:

    MONTHS(Start Date; End Date)

    and that’s it!

    It’s not required to learn to program in JavaScript just to do simple things like that. That’s what the Calculation field is for. There’s lots of functions that’ll do all sorts of things for you without programming. You just have to know simple mathematical expressions.

    Thanks,

    Brendan

    #48624

    In reply to: add & subtract

    Brendan
    Keymaster

    Hi Glen,

    You would not use the square brackets around [today] and [purchased].

    In JavaScript there’s a getMonth() function you can use on dates.

    So your formula would be:

    var duration = today.getMonth() - purchased.getMonth();

    FYI, NaN stands for Not a Number

    #48614

    In reply to: Learning JavaScript

    Glen Forister
    Participant

    Disappointed…
    I didn’t know I would have to spend a week or more to learn Javascript to add or subtract two fields. Spent the greater part of a summer recently learning “R”, but now I can barely get started again. Use it or lose it. I don’t want to spend a week to do a simple calc to get a form to do something and then a month or year late have to go through all that again. This isn’t simple…

Viewing 15 results - 646 through 660 (of 2,951 total)