Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
February 5, 2023 at 4:35 PM #48844
In 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 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();January 18, 2023 at 10:10 PM #48709In reply to: List with Check box
Glen Forister
ParticipantThat 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”.
-
This reply was modified 3 years ago by
Glen Forister.
January 18, 2023 at 10:01 PM #48707In reply to: Date sorting problem
Glen Forister
ParticipantNope. 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.January 18, 2023 at 9:09 PM #48703In reply to: List with Check box
Brendan
KeymasterIn 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.
January 18, 2023 at 7:03 PM #48695In reply to: Day of Year
Daniel Leu
ParticipantWell, 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])+1It looks complex but it isn’t:
1)
DATE([Date day Collect];"yyyy")extracts the year from yourDate day Collectfield. The square brackets are only an optical indicator.
2)NEWDATE(...)creates the date for January 1st of yourDate day Collectyear.
3)DAYS()calculates the days between two dates, theJanuar 1st Date day CollectandDate day Collect.
Then it’s just adding 1 to get the result. The return value isnumber.Attached is the formula in my editor. I used your rain collection data where
dateequalsDate day Collectin 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 -
This reply was modified 3 years ago by
-
AuthorSearch Results