Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
February 7, 2023 at 11:41 AM #48857
Topic: Date listed only if recurr
in forum Using Tap Forms 5Glen Forister
ParticipantI 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.
February 6, 2023 at 12:43 AM #48849In reply to: Import data from JSON file
Brendan
KeymasterMake 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.
February 5, 2023 at 9:56 PM #48847In reply to: Import data from JSON file
Chris Ju
ParticipantHi 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)
February 5, 2023 at 5:40 PM #48845In reply to: Result from one field in another field – same form
Daniel Leu
ParticipantOne 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&tricksFebruary 5, 2023 at 4:35 PM #48844In reply to: Result from one field in another field – same form
Bil Stallman
ParticipantThanks 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.
February 5, 2023 at 3:35 PM #48842In reply to: Result from one field in another field – same form
Brendan
KeymasterHi 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
February 5, 2023 at 2:43 PM #48839In reply to: Import data from JSON file
Brendan
KeymasterHi 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.February 5, 2023 at 2:21 AM #48838In reply to: Import data from JSON file
Chris Ju
ParticipantThanks, 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?
February 4, 2023 at 11:17 AM #48836In reply to: Import data from JSON file
Daniel Leu
ParticipantWhat 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&tricksFebruary 4, 2023 at 5:54 AM #48834Topic: Import data from JSON file
in forum Script TalkChris Ju
ParticipantHi 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
ChrisGlen Forister
ParticipantThe 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.
January 25, 2023 at 11:33 AM #48790Topic: Due date
in forum Script TalkGlen Forister
ParticipantLooks 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.
January 19, 2023 at 8:17 PM #48735In reply to: List with Check box
Brendan
KeymasterWell 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.
January 19, 2023 at 10:48 AM #48724In reply to: List with Check box
Glen Forister
ParticipantI 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.January 18, 2023 at 10:46 PM #48715In reply to: List with Check box
Brendan
KeymasterThe
Advanced Find & Replacefunction is under the Records menu on the Mac version.There’s a script snippet called
Basic Loopwhich just sets up a loop. But you would have to fetch the records first withvar records = form.getRecords();and then get each record within the loop and then set the value of the field using therecord.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
Shieldfield 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(); -
This reply was modified 3 years, 3 months ago by
-
AuthorSearch Results