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 - 586 through 600 (of 2,951 total)
  • Author
    Search Results
  • #49043
    Glen Forister
    Participant

    I ran across a Script function defined to copy a record from form to another.
    function Copy_Record_To_Form()

    See attached. I have two forms, each with hundreds of records which I add to frequently. The problem is they were made at different times for different reasons and both contain much of the same information. Is it possible to fill out a new record in one of the records and somehow copy the information that is common to both to the other Form? Going in one direction from one to the other, depending on which form gets filled out first and then need to fill out a record in the other form?

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

    Hi Jon,

    You could try the Utils.openUrl() method.

    This would work to create the email. It’ll launch your mail program and put in the subject and body.

    function Email_User() {
    
        let subject = encodeURIComponent("Testing 123");
        let body = encodeURIComponent("This is what I want to say in the email");
        Utils.openUrl("mailto:support@tapforms.com?subject=" + subject + "&body=" + body);
    
    }
    
    Email_User();

    You would have to put the script into a Script Field on your Table field though. Then you’ll have to reference your Date field in your script, which will cause the trigger and add a check to see if the date is today before running the above code.

    #49034

    In reply to: If loop

    Glen Forister
    Participant

    It works, but as I feared, I notice these equations return integers, not actual decimal numbers indicating parts of an integer. I guess I have to do this in Script to get a real value???

    I was able to get YEARS AND MONTHS, but not a real value, just an approximated value. Number Format is decimal with 2 places.

    See pic attached.

    Attachments:
    You must be logged in to view attached files.
    #49028
    Jon Millar
    Participant

    Hi All. Loving TapForms so far,

    Is there any way to create a script that will run automatically when a record date field from a table = todays date?

    Any help gratefully revived
    Cheers
    Jon

    • This topic was modified 2 years, 8 months ago by Jon Millar.
    #49020

    In reply to: Learning JavaScript

    footlooseboss
    Participant

    for future readers as much as OP:

    Can someone recommend any books, videos, etc. to learn JavaScript, particularly in relation to Tap Forms 5 rather than web use?

    I used Khan Academy to teach myself further maths; they have a course on JavaScript. I found it better than a real tutor (pause + rewind). Probably start with a few modules here.

    I learnt two ways:
    – downloading the source of a website, modifying it, breaking it, fixing it
    – setting a goal of writing a script to do something useful on a webpage automatically – in my case it was logging into a booking website every day, finding available time slots, and booking the first slot before anyone else

    I can suggest tools but to start experimenting just enable the developer menu in Safari, and open inspector/console.

    Tap Forms API reference:
    tapforms.com/help-mac/5.3/en/topic/javascript-api

    Tap Forms scripting videos (fairly in-depth, probably don’t start here)
    pasamio YouTube

    edit: format

    • This reply was modified 2 years, 8 months ago by footlooseboss.
    #48992

    In reply to: Prompter issue

    Sam Moffatt
    Participant

    I think the snippet is ok, it’s just if you run the snippet inside of a function it’ll insert it there. I think an improvement for a future prompter would be a way of having the callback accept the return values as a dictionary which would remove the need to have the variables defined at the right scope (which for Javascript is a challenge at times).

    #48988

    In reply to: days between dates

    Brendan
    Keymaster

    There are all sorts of functions you can perform on JavaScript Date objects without having to do the math yourself:

    https://www.w3schools.com/js/js_date_methods.asp

    #48986

    In reply to: days between dates

    Glen Forister
    Participant

    Of course. How did I miss that.
    It does work.
    I have some work to do to understand the scripts you have given me, so thanks for that.

    Also, thanks for the calc info “In Javascript, the Date object represents the time in milliseconds since January 1, 1970, UTC. So the difference needs to be divided by milliseconds-per-day.”

    I will need that in another Form I just used the above script on and it worked. I have to know the weeks and months, not just days.

    #48985

    In reply to: days between dates

    Brendan
    Keymaster

    You need to put in your own field ID instead of fld-xxx as in Daniel’s sample script. He doesn’t know what your field ID is, so we often just put in stand-ins for a field ID. It’s something you have to substitute yourself when you see any code here. Field IDs are unique to your own forms.

    #48976
    Sam Moffatt
    Participant

    Those of you who have been looking at my YouTube might have seen the video talking about Managed Fields and I’m finally ready to show it to the world. This is brand new, probably has a few bugs and definitely isn’t as battle tested as some of the other code I’ve written as I had a more immediate need to leverage it. It’s already up to 1.0.1 because I found a bug with the log feature (I forgot to include the record ID! Doh!) and also wanted to include my old setIfEmpty feature as a part of managed fields as well making it easy to only update fields whose values aren’t already set in addition to a couple of other options.

    Those curious might also be interested in the VOD of Twitch stream I did which has some more development included though has some distractions as well. You can see in real time just how slow building some of this code up is though I must apologise the audio quality ended up quite poor.

    A big part of Managed Fields are two accompanying forms in addition to the Managed Field script library. Check out the attachment to this post (you’ll need an account to download) and import it to your record alongside the original Script Manager. I’ve also started to add some Markdown documentation and you can see an example with the addToTableIfMissing. I’m slowly adding documentation for various things as I come back to using them and forget how they work so hopefully also sharing. At some point I hope to leverage the Markdown feature in Tap Forms to include these inside the database so the documentation is always available…even if you’re working on your Tap Forms document on the plane!

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

    In reply to: days between dates

    Daniel Leu
    Participant

    I got several errors when I tried to run your code. This touched-up version works for me:

    var date_id = 'fld-xxx';
    
    function Days_Between_Dates(){
    	console.log("Days_Between_Dates() called ...");
    
    	var days = -1;
    	var records = form.getRecords(); // calls function getRecords()
    	var currentRecordIndex = records.indexOf(record);
    
    	if (currentRecordIndex > 0) {
    		var previousRecord = records[currentRecordIndex-1];
    	} else {
    		return -1;
    	}
    
    	// get the two dates
    	const today = record.getFieldValue(date_id);
    	const previous_day = previousRecord.getFieldValue(date_id);
    	
    	// calculate the difference between the two date objects
    	days = Math.round((today - previous_day) / (1000 * 60 * 60 * 24));
    
    	console.log("today: " + today)
    	console.log("previous day: " + previous_day)
    	console.log("difference: " + days)
    	
    	return days;
    }
    
    Days_Between_Dates()

    In Javascript, the Date object represents the time in milliseconds since January 1, 1970, UTC. So the difference needs to be divided by milliseconds-per-day.

    I changed the return value to -1 for the first record.

    When reporting a syntax error, it’s helpful to have the entire message.

    When posting code, please encapsulate it in back-ticks. This way it is easier to copy&paste it and it looks prettier. Thanks!

    Cheers & happy hacking!

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

    Cheers, Daniel

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

    #48968

    In reply to: days between dates

    Brendan
    Keymaster

    I see what you did. You copied Daniel’s code and put it inside your script after you had already defined the function.

    What he meant by this part:

    function Days_Between_Dates(){
       console.log("Days_Between_Dates() called ...");
       ...
    }

    Was take your existing script and just below the function declaration, put in the console.log() call. Not duplicate the function definition again.

    Then after your function definition, actually call the Days_Between_Dates() function which your original script did not show you were doing.

    #48965

    In reply to: days between dates

    Brendan
    Keymaster

    I’m a bit confused with your script. Did you define Days_Between_Dates() twice?

    Or was that a typo in your post?

    I also edited your post to put the back-ticks in so your code was easier to read.

    • This reply was modified 2 years, 8 months ago by Brendan.
    #48959

    In reply to: days between dates

    Daniel Leu
    Participant

    Do you have a Days_Between_Dates(); at the end of the script after the closing bracket of the code you showed? This causes your function to be called.

    If you run this script on the first record, it will not do anything since it is the first record.

    Sometimes I add something like this to my functions:

    function Days_Between_Dates(){
       console.log("Days_Between_Dates() called ...");
       ...
    }
    
    Days_Between_Dates();

    This way I can easier trace what’s going on with my scripts.

    Cheers, Daniel

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

    #48954

    In reply to: days between dates

    Glen Forister
    Participant

    Ok, missed that.
    But I got all the syntax cleared and this script does nothing, not even printing to console the variable values. So I’ve proved I haven’t learned anything yet.
    Any ideas?
    Thanks.

    
    function Days_Between_Dates(){
    	var date_id = ('fld-119ad5683104451ca6855e777a23ad21');
    
    	
    	var records = form.getRecords();   // calls function getRecords()
        	var currentRecordIndex = records.indexOf(record);
    
        	if (currentRecordIndex > 0) {
            	var previousday = records[currentRecordIndex-1];
        	} else {
         		return 0;
        	}
        	
        var today = record.getFieldValue(date_id);
        var previous_day = previousRecord.getFieldValue(date_id);
        var total = today - previousday;
        
        
        console.log("today: ")
    	console.log("previousday: ")
    	console.log("total: ")
        
        return total;
    }
    
    
    • This reply was modified 2 years, 8 months ago by Glen Forister.
Viewing 15 results - 586 through 600 (of 2,951 total)