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 - 661 through 675 (of 2,989 total)
  • Author
    Search Results
  • #48844
    Bil Stallman
    Participant

    Thanks Brendan. I did have a go at scripting via the scripts tab but I have very limited JavaScript programming knowledge. It is something to learn. I will also play around with Link to Form. Maybe a more detailed look into the help sections.

    #48842
    Brendan
    Keymaster

    Hi Bil,

    Something like this could be done with a Script field that monitored the value from your field that contains the names and then sets a Website Address field to a website when you select it. Your script would probably have to have the list of corresponding website addresses in it though.

    I’m not sure how well versed you are in JavaScript programming though.

    You could also use a Link to Form field that contains a list of names and corresponding website addresses. Then when you assign the child record to your parent record, you would see the name and website address. The website address on the child form would be a Website Address field. At least you would want it to be.

    Thanks,

    Brendan

    #48839
    Brendan
    Keymaster

    Hi Chris,

    Well, what you probably have is an array of dictionaries in your JSON.

    So your data variable is probably just that. So you need to iterate over the array and pick out the values, create a new record for each entry in the JSON file and set the field value on it.

    Here’s an example script that does that to import a file of time zones.

    function Import_Time_Zones() {
    
        var time_zone_name_id = 'fld-1b8bca6459724faabec0d3f7a1b3e4e4';
        var country_id = 'fld-69acd4190b974d678a6e662308d580d7';
        var name_id = 'fld-4dc0850299c64960b480a3593bbdfad0';
    
        let url = 'file:///Users/brendan/Desktop/CitiesAndTimeZones.json';
        let cities = Utils.getJsonFromUrl(url);
    
        for (let index = 0; index < cities.length; index++) {
            let city = cities[index];
            let name = city.name;
            let country = city.country;
            let time_zone_name = city.timeZoneName;
            let newRecord = form.addNewRecord();
            newRecord.setFieldValue(name_id, name);
            newRecord.setFieldValue(country_id, country);
            newRecord.setFieldValue(time_zone_name_id, time_zone_name);
        }
        form.saveAllChanges();
    }
    
    Import_Time_Zones();

    I’ve attached the JSON file if you want to play around with it.

    One very helpful technique when dealing with JSON files, is use the JSON.stringify() function to see what kind of data you get from your JSON file.

    #48838
    Chris Ju
    Participant

    Thanks, that’s useful. But with my little experience with java script it isn’t possible for me to get a reliable result. Maybe someone else has solved that in the past and could give some hints.

    Especially if one have a JSON file with multiple “datasets”, looping through the “datasets” and adding a new entry in TF for every “dataset” is difficult to understand for me :-( … but i’m working on it…

    @Brendan (if you read this): Wouldn’t it be easier to introduce an import option for JSON files? JSON is also only a table in some way… or am I thinking wrong?

    #48836
    Daniel Leu
    Participant

    What a coincidence, I’m working on getting JSON data into TF right now as well. My data is on the clipboard. So I import it from there. Next I translate it into a javascript data object. Then loop over the different entries.

    For you, since not all records have the same fields, you need to check for valid content like I do with customer.name.

    let customersJSON = Utils.copyTextFromClipboard();
    let customers = JSON.parse(customersJSON);
    
    for (let customer of customers){
    	if (customer.name){
    		console.log("Processing customer name: " + customer.name);
    	} else {
    		// missing customer name branch
    	}
    }
    

    Hope this helps you get started.

    Cheers, Daniel

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

    #48834
    Chris Ju
    Participant

    Hi everyone,

    I would like to import data from a JSON file. The fields should be filled accordingly. Here is an example of a JSON file with one record. Retrieving the entire file is no problem with

    var data = Utils.getJsonFromUrl(url);

    … but I want to fetch them one by one and populate the fields in the form’s record.

    I think it is easy, but i’m still not handy with java script.

    Easyest way would be from the import dialog, but that doesn’t work.

    Thanks
    Chris

    #48793

    In reply to: Due date

    Glen Forister
    Participant

    The due date is different for each record.
    2 fields are used here
    1 -Original date of event.
    2 – days until next thing is due.
    It doesn’t look like you can use a field in the option “D”.
    DATEADD(Date;Y;M;W;D;H;M;S)

    Looks like D has to be a set number, not a var from another field. That is why I thought a script would be needed.

    #48790

    Topic: Due date

    in forum Script Talk
    Glen Forister
    Participant

    Looks like I have to use Javascript to get a due date. How do you do this?

    Add a number of days to a calendar date to get a due date.

    #48735

    In reply to: List with Check box

    Brendan
    Keymaster

    Well the script is specific to the form because it’s referencing fields within the specific form. So ya, you need it in every form if you want the same behaviour in every form. Alternatively, a more advanced script could loop through all records of every form and look for specific fields to update to reset the checkmark field values.

    #48724

    In reply to: List with Check box

    Glen Forister
    Participant

    I thought I had failed to make it work, but then I remembered you said that was for the iPhone, so tried it there and it did work.
    Thanks.

    Seems like I have to install that script to every FORM which isn’t ideal, but will work.

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

    In reply to: List with Check box

    Brendan
    Keymaster

    The Advanced Find & Replace function is under the Records menu on the Mac version.

    There’s a script snippet called Basic Loop which just sets up a loop. But you would have to fetch the records first with var records = form.getRecords(); and then get each record within the loop and then set the value of the field using the record.setFieldValue(some_checkmark_field_id, 0); function. The 0 would set the checkmark field value back to off.

    Don’t forget to do a form.saveAllChanges(); outside of the loop at the end before the program ends so Tap Forms can save the values.

    This Form Script will reset all the checkmark fields for your Shield field back to OFF:

    function Reset_Shields() {
    
    	var shield_id = 'fld-d13c2bafe6e8482288c551bd8c931373';
    	var records = form.getRecords();
    	
    	for (var index = 0, count = records.length; index < count; index++){
    		var theRec = records[index];
    		theRec.setFieldValue(shield_id, 0);
    	}
    	form.saveAllChanges();
    }
    
    Reset_Shields();
    #48709

    In reply to: List with Check box

    Glen Forister
    Participant

    That sounds good.
    1. Where is that find and replace? I tried the Edit/Find & Replace in the menu, but all I could find was the “Find” in the upper right corner, no replace. Or, do you have a library of scripts that I can find that in? “check mark” = 0 & 1. I get that.

    2. When I’m in the filed, I will definitely need a script. Is that in this library of scripts?
    Thanks.

    I didn’t see where on the iPhone I would find that script. I didn’t see it in the “Tools”.

    #48707

    In reply to: Date sorting problem

    Glen Forister
    Participant

    Nope. Not on my iPhone 6s running 15.7.2

    I have many records each month. Between each month is a divider stating the name of the month (January, February, etc.). As I scroll down (records are sorted down in ascending order) and the first month divider (which I did not ask for nor is part of my data) hits the top and the headers for the columns disappear.

    But you seem to think this is standard as I read your response again. That isn’t right.
    I can go down, come up a ways, go down, anywhere in the list of records and I will never see the definitions of each column, the column headers. I never see them again until I get back to the first month divider and then the headers appear again. Throughout the whole time I can’t see what the identity of each column until I am at the top of the database and the 1st month divider scrolls down below and allows the headers to appear.
    Does that describe it? See attached file.

    While you are seeing this file, maybe you can tell me why the 2 scripts I’ve been given to allow me to see just 1 season of rain with the total rainfall in that 1 season view 22-23 starts at the beginning of the season with the total of 80.95 instead of 0.331 which is the total. for the 1st rain of the season.

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

    In reply to: List with Check box

    Brendan
    Keymaster

    In Tap Forms for Mac there’s a Find & Replace function which can do this sort of operation.

    For iOS you’d need to write a script that loops through all your records and resets the Checkmark fields to 0 (off) if you wanted to quickly start again.

    #48695

    In reply to: Day of Year

    Daniel Leu
    Participant

    Well, my first thought was a Javascript script… ;-) But then I wondered if the calculation field might do the trick. Yes, and here is the solution:

    DAYS(NEWDATE(DATE([Date day Collect];"yyyy");1;0;0;0;1;0;0;0);[Date day Collect])+1

    It looks complex but it isn’t:

    1) DATE([Date day Collect];"yyyy") extracts the year from your Date day Collect field. The square brackets are only an optical indicator.
    2) NEWDATE(...) creates the date for January 1st of your Date day Collect year.
    3) DAYS() calculates the days between two dates, the Januar 1st Date day Collect and Date day Collect.
    Then it’s just adding 1 to get the result. The return value is number.

    Attached is the formula in my editor. I used your rain collection data where date equals Date day Collect in your graphic. I did this on my desktop.

    Here is the link to the calculation field documentation: https://www.tapforms.com/help-mac/5.3/en/topic/calculation.

    Have fun!

    • This reply was modified 3 years ago by Daniel Leu.
    • This reply was modified 3 years ago by Daniel Leu.
    Attachments:
    You must be logged in to view attached files.

    Cheers, Daniel

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

Viewing 15 results - 661 through 675 (of 2,989 total)