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 - 721 through 735 (of 3,053 total)
  • Author
    Search Results
  • #48857
    Glen Forister
    Participant

    I have a journal that has items that need a date listed for when It should recur next.

    I don’t want a value in that field unless the checkbox “Recur” is checked.
    Does this take script or can it be done with an if statement.

    I just wanted to know before I made a new Form to play with because I know I’ll lose all my data if I play with this one.

    #48849
    Brendan
    Keymaster

    Make sure that you set the Script folder on the Preferences window to your Desktop folder before you run the script. It’s probably not able to read the file due to security restrictions in macOS.

    #48847
    Chris Ju
    Participant

    Hi Brendan, thanks for that example script. It works, if i get the JSON data from clipboard.

    Using your original script to get the JSON data from file:


    ...

    let url = 'file:///Users/jur/Desktop/CitiesAndTimeZones.json';
    let cities = Utils.getJsonFromUrl(url);
    console.log(cities);

    for (let index = 0; index < cities.length; index++) {

    ...

    results to:


    undefined
    Import Time Zones: TypeError: undefined is not an object (evaluating 'cities.length'), line:(null)

    #48845
    Daniel Leu
    Participant

    One cool feature in TF is that picklist entries can come from a form. So I have a form called ‘Brands’ that contains name and URL fields. I select this form to be the source of my picklist. Then in my main form, I use that picklist to select the brand. Further, I use a field script ‘URL Script’ to set the value of the URL field. The field script is triggered whenever a different brand is selected and then the URL field is updated accordingly.

    When the script is triggered, it fetches all entries of the ‘Brands’ form and loops through them. Once a match is found, the URL field is set according to that matching record entry and the script aborted:

    function Url_Script() {
    
     	var brand_id = 'fld-feb500eed99747169d8d90db3a620243';
    	var url_id = 'fld-0a342472ca0b44b1a52c3758c5be92e4';
    
    	const brands_name_id = 'fld-8d373c0912154c69a7f579e696cd598c';
    	const brands_url_id = 'fld-0a342472ca0b44b1a52c3758c5be92e4';
    
    	let brand = record.getFieldValue(brand_id);
    	
    	// get the brands form. Note that the name of the form must match!
    	let brandsForm = document.getFormNamed("Brands");
    	
    	for (let rec of brandsForm.getRecords()){
    		if (rec.getFieldValue(brands_name_id) == brand){
    			let url = rec.getFieldValue(brands_url_id);
    			console.log("found match: " + brand) + " with url " + url);
    			record.setFieldValue(url_id, url);
    			document.saveAllChanges();
    			return url;
    			break;
    		}
    	}
    
    }
    
    Url_Script();
    

    Hope this is what you were looking for. I have attached my example document.

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

    Cheers, Daniel

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

    #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.

    • This reply was modified 3 years, 3 months ago by Glen Forister.
    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();
Viewing 15 results - 721 through 735 (of 3,053 total)