Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
July 16, 2021 at 9:18 AM #44812
In reply to: Gear check list
Sam Moffatt
ParticipantLooking at the sample checklist I’d probably structure four forms:
– Template: blue columns; the category heading (e.g. “footwear”) is another field. Add a checklist for “active”.
– Hikes: hike metadata of when, where, etc that isn’t checklist related.
– Checklist: green columns; the category heading (e.g. “footwear”) is another field.
– Gear: simple form with your gear information normalised.Category heading is another field because it’s really a property of each row in that spreadsheet but we need to tell the computer that. Tap Forms has a spreadsheet like view, the multicolumn list view (MCLV), and you can use the grouping feature to recreate the column heading.
I’d model Hikes as being linked to Checklist and Checklist having a link to Gear. You might want to add a “default gear” field to the template that can be used as well for stuff you almost always use (same sun glasses). From there I’d likely look at scripting to create a “hike” and then create new checklist records, linked to the hike, from the template records. I added the “active” field to the template so that you can use a saved search on active records when creating the checklist items. It allows you to have a template item that isn’t copied easily.
On my YouTube channel, I have a <a href=
“https://www.youtube.com/watch?v=TB4EavvTihQ&list=PLyMabv86X9YFlGFdj5BWszcgYd9cSc-Jw”>playlist on building a meal planner which includes a shopping list that is built on the fly. Episode 3 introduces the shopping list and covers how to create “trips” with items from the list that haven’t been bought yet. A similar approach could be used where instead of a shopping list, it’s your template form and you create a hike from it and copy the entries over to the checklist. I made some tweaks in later episodes to the scripts for QOL but episode three demonstrates finding records, creating a new one and linking them together. The video on processing semistructured data into records also covers a use case where I’m copying data to create a new record though the focus parsing there.On the value replication for stuff like weight, you can use a calculation field to copy field values from parent of link to form 1:M though going the other way requires scripting to handle multiple values.
Bit of a mind dump, hope this helps!
July 16, 2021 at 6:47 AM #44810Topic: Gear check list
in forum Using Tap Forms 5Juha Ranta
ParticipantHi,
I’ve already made an inventory of my hiking, travel, trail running etc gear in Tap Forms. I like having the gear information, personal notes, weight, etc with me.
Now, I’m trying to create something like this Andrew Skurka gear list for travel/hiking list. https://andrewskurka.com/backpacking-gear-list-template-checklist-3-season/
I have the gear in Tap Forms already. I’ve been thinking of different options to create this kind of a gear list. In the end I’d like to export is as a Taskpaper/OmniFocus list.
I did it this it this time by exporting from Tap Forms as CSV, then importing the items with their weight in Google Sheets. It was plenty of manual work.
I wonder if there’s a good way to implement this kind of a system in Tap Forms. It would need:
– Topics for things like
– Utilities
– Clothing
– Food
– Reference to select a tool from the gear list in Tap Forms
– Way to calculate total count, maybe some more complicated calculations, such as in back / clothed on me
– A default template that has the typical gear that’s with me for a backpacking hike for instanceSo I was thinking if this kind of a gear list system is easy to do with Tap Forms, or maybe I should export to csv, import to some spreadsheet software, etc. I work as a software engineer and can do scripting too with Ruby, Python, etc. I’m not just sure about what’s the best way to implement this kind of a thing at the moment, so I’d appreciate feedback. Thanks!
July 16, 2021 at 3:16 AM #44809Konrad Schoettl
ParticipantNo, there isn’t a circular reference as you described. I think I have found the reason for the crash. This occurs only with more than one ‘Link to Form’ field defined (in my case, there were two fields, each ‘many to many’). With only one such field, the export including the linked records works fine. But anyway, the export doesn’t work as I expected. I get several separated CSV files. But I wanted to get one file, containing also the linked records. For my book example, I wanted to export all books from the book form, including the author’s names from the author form. But the column for the author’s names (Link to Form) is empty.
I found another solution for this purpose. I defined a script field in the book form that copies the author’s names into the book form. Now I can export the books with all author’s names into one file, what is what I wanted ?.
Thanks
KonradJuly 14, 2021 at 5:49 PM #44803In reply to: Saved Search for Photo Field
Daniel Leu
Participant2 – If it isn’t in fact possible to search attachment fields, is there another way to do this?
You can use a field script and use following code. This will return 0 if there are no photos and 1 if there is at least one photo. You just need to add the ID of your Picture field.
function Has_Photo() { let photo_id = 'fld-xxx'; let photo = record.getFieldValue(photo_id); if (photo.length > 0){ return 1; } else { return 0; } } Has_Photo();Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksJuly 14, 2021 at 3:40 PM #44801In reply to: Count down timer or open count down app
Sam Moffatt
ParticipantMaybe you could maker a timer/countdown app that supported x-callback-url and could be used in combination with scripting or URL fields in TF.
July 9, 2021 at 7:03 PM #44775In reply to: Run script on record change / save
Kenneth James
ParticipantThank you. I knew of the distinction, and I even found my Java Script book to verify and all I was seeing were examples for the assignment designation – the single “=”. It just didn’t occur to me that that was the problem.
Problem solved!
Thank you
KDJJuly 9, 2021 at 1:00 PM #44770In reply to: Run script on record change / save
Kenneth James
ParticipantI am misunderstanding something about how and when scripts are triggered and when they fire. My use case: Trying to set a toggle switch (CheckMark field) in a record that will populate a default value in the Location field, otherwise, just leave the Location field alone.
The script in the Script Field.
function Default_Location() { var useDefault = record.getFieldValue('fld-332bc0f45e1d4a9bbcf6b90d0087234e'); console.log(useDefault) if (useDefault = false) { // the check mark is NOT checked meaning add the default location record.setFieldValue('fld-e83fedb15a0d4a09be818513c2a0f4e5', JSON.parse({
“altitude”: “849.74”,
“heading”: “-0”,
“lat”: “46.9999999”,
“lon”: “-118.99999999”,
“pitch”: 0,
“title”: “123 Main Street, Anywhere, United States”}`))
// my actual home address goes here!
}
}
Default_Location();`What happens:
Add a new record:
CheckMark field = unchecked (i.e. false)
Location field = blank (what it should be)While in the record, I check the CheckMark field indicating that the Location field should be auto-populated with the default value.
CheckMark field = checked (i.e. true)
Location field = still blank, nothing happens.Close the record and move to another record
Go back to the previous record and re-open it.
CheckMark field = checked (i.e. true)
Location field = still blank, nothing happened.IF I REVERSE THE LOGIC IN THE SCRIPT, change the if (useDefault = true), THEN a new record is populated automatically with the default location while the CheckMark field is unchecked.
Something is not behaving like I anticipate that it should be behaving.
Obviously, I am missing something.
Thanks for any advice.
Kenneth James
July 8, 2021 at 10:01 AM #44757In reply to: How to simulate nested pick lists
Sam Moffatt
ParticipantYou can bulk import to the pick list or if you already have much of the structure defined you could use a form field as a source and import data into the form with a field per layer of your tree.
Attaching a form template with up to 9 layers to show how scripting can be used to build it. Import the template, fill in some values and then in the pick list setting set it up with the use values from field option (see screenshot). As you do each layer, you can duplicate the record and update the value you need to change. Should make data entry a little less error prone. Trees are rather unwieldily to deal with unfortunately.
Attachments:
You must be logged in to view attached files.July 7, 2021 at 10:46 AM #44738In reply to: pick-list within a pick-list
Sam Moffatt
ParticipantSince this was posted in 2014, that’s still TF3 (desktop)/TF4 (iOS) so since then TF5 came out with support for multiple documents, leveraged a new data backend, nearby sync and CouchDB/Cloudant Sync options, image fields supporting multiple images and a pop out gallery view, the scripting engine, the charting system, access controls on the Mac, the markdown field type as well as improvements to various smaller features (e.g. extra functions for the calc system). Almost all features are parity between iOS and Mac as well (layouts I think is the biggest one missing from iOS). You can check out the 5.3.19 changelog for all of the changes in the TF5 series up to the current version.
I believe the current focus is to move to a newer data backend due to it not being supported any more and not being able to build against newer targets.
July 5, 2021 at 12:01 AM #44718In reply to: Split note field?
Sam Moffatt
ParticipantI turned this into a video using the above sample data and script as a basis including building out two forms to track the data. I’m going to do a follow up video on how to handle the multiline fields which isn’t currently handled for next week.
June 27, 2021 at 10:14 AM #44687In reply to: Client – Invoice – Tax Forms
Sam Moffatt
ParticipantIf you’ve on the child side of a 1:M relationship then you can use a calculation field or script field to copy the value of any field from the parent record.
If you’re using M:M relationships, you’ll need a script field to merge the data together.
I have a video covering some of this on YouTube with a library linking example and another one on using link to form fields and duplicating field values.
June 22, 2021 at 6:35 AM #44667Topic: Limitations on access to where databases are stored
in forum Using Tap Forms 5DrJJWMac
ParticipantBy default, Databases for Tap Forms are stored (deeply nested) in a folder in the user’s library folder. I prefer to store my databases on a separate volume / drive. I tried to put a symlink in the default sub-folder to point to my storage folder with the hope that I could see into the volume at the splash-screen dialog box. This did not work.
I can see preferences to change the default locations for backups and scripts. But nothing can be done to set the default for databases, and the splash-screen does not allow easy access to a different location (outside the user’s library).
I’d hope perhaps the limitations can be lifted for a future version.
June 21, 2021 at 11:48 PM #44663In reply to: Split note field?
Sam Moffatt
ParticipantOk, so if you’ve got multiple entries then I’d suggest creating a second form for the data and using a link to form field to store that data in or a table field. This allows you to model the multiple entries but link it back to the main record.
This script is a little longer than the last. I’ve put comments throughout it. You’ll need to fill in the blanks for the field ID’s which you can find via the script editor by clicking on the field and hitting ID or by looking at it’s ID in the field details panel.
The way I’ve constructed it is something that could be optimised but I use this technique to verify the object that is constructed looks “right” and then I add in the piece to
addNewRecordToFieldandsetFieldValueat the end which actually creates the records.Here’s the script:
// fieldNames is a list of field names for each line. const fieldNames = [ 'event_date', 'squadron', 'location', 'aircraft', 'pilot', 'damage_type', 'comments' ]; // aircraft details has the fields for the aircraft line. const aircraftDetails = ['aircraft_type', 'aircraft_sn', 'aircraft_ext']; // fieldMap maps the friendly field name to the Tap Forms field name. // these are the fields IDs from the link to form or table field const fieldMap = { "event_date": "fld-001", "squadron": "fld-002", "damage_location": "fld-003", "damage_description": "fld-004", "damage_percentage": "fld-005", "aircraft_type": "fld-006", "aircraft_sn": "fld-007", "aircraft_ext": "fld-008", "pilot_rank": "fld-009", "pilot_name": "fld-010", "damage_type": "fld-011", "comments": "fld-012" }; // input is our sample data, in your script: // let input = record.getFieldValue('fld-notefieldid'); let input = `02.08.1942 12 Squadron RAF Hawkinge, tire burst on landing (20%) Lancaster1, SN.ZX334 SqnLdr. Conran 1) RAF Bomber Accidents 1) no comment. 02.08.1942 12 Squadron RAF Detling, dmage while on sortie (50%) Lancaster1, SN.ZX334, BA- SqnLdr. Conran 1) RAF Bomber Damage 1) no comment. 17.08.1943 61 Squadron Hamburg, Shot down by a nightfighter (100%) Lancaster1, SN.ZX334, BA- SqnLdr. Hewitt 1) RAF Bomber Losses 1) no comment.`; // lineIndex the index of the line we're processing. let lineIndex = 0; // parsedData is an object we're going to put the data in temporarily. let parsedData = {}; // lines is each of the lines let lines = input.split("\n"); // process each line... for (let line of lines) { // trim the line of extra whitespace line = line.trim(); // ignore empty lines. if (line.length == 0) { continue; } // handle each line we're working on switch (lineIndex) { // these lines pass thru the value 1:1 case 0: case 1: case 5: case 6: parsedData[fieldNames[lineIndex]] = line; break; case 2: // damage line is field1, field2 (field3) so let's parse that: let damagePieces = line.match(/([^,]*), (.*) \((.*)\)/); if (damagePieces && damagePieces.length > 2) { parsedData["damage_location"] = damagePieces[1]; parsedData["damage_description"] = damagePieces[2]; parsedData["damage_percentage"] = damagePieces[3]; } break; case 3: // aircraft line appears to have two or three entries so we split let aircraftPieces = line.split(',').map(elem => elem.trim()); // then we work through each piece of the split line for (let aircraftIndex in aircraftPieces) { // and put it in the relevant field parsedData[aircraftDetails[aircraftIndex]] = aircraftPieces[aircraftIndex]; } break; case 4: // pilot appears to be a simple space split field with two values. let pilotPieces = line.split(' ').map(elem => elem.trim()); parsedData["pilot_rank"] = pilotPieces[0]; parsedData["pilot_name"] = pilotPieces[1]; break; default: console.log("Unknown Line"); console.log(lineIndex); console.log(line); } // increment lineIndex to change which line we think we're processing lineIndex++; // if lineIndex becomes 7, we're at the end of this stanza if (lineIndex > 6) { // reset the lineIndex back to zero lineIndex = 0; // log out our parsed object. console.log(JSON.stringify(parsedData)); // create a new entry in our link to form field // remove the /* and */ lines after testing /* let newEntry = record.addNewRecordToField("fld-linktoformfieldid"); for (let fieldName in parsedData) { // set the field value of the field to the value we parsed. newEntry.setFieldValue(fieldMap[fieldName]), parsedData[fieldName]); } */ // reset the parsedData object to empty. parsedData = {}; } } // save all the changes we made! document.saveAllChanges();For the sample data, the console log looks something like this:
{"event_date":"02.08.1942","squadron":"12 Squadron","damage_location":"RAF Hawkinge","damage_description":"tire burst on landing","damage_percentage":"20%","aircraft_type":"Lancaster1","aircraft_sn":"SN.ZX334","pilot_rank":"SqnLdr.","pilot_name":"Conran","damage_type":"1) RAF Bomber Accidents","comments":"1) no comment."} {"event_date":"02.08.1942","squadron":"12 Squadron","damage_location":"RAF Detling","damage_description":"dmage while on sortie","damage_percentage":"50%","aircraft_type":"Lancaster1","aircraft_sn":"SN.ZX334","aircraft_ext":"BA-","pilot_rank":"SqnLdr.","pilot_name":"Conran","damage_type":"1) RAF Bomber Damage","comments":"1) no comment."} {"event_date":"17.08.1943","squadron":"61 Squadron","damage_location":"Hamburg","damage_description":"Shot down by a nightfighter","damage_percentage":"100%","aircraft_type":"Lancaster1","aircraft_sn":"SN.ZX334","aircraft_ext":"BA-","pilot_rank":"SqnLdr.","pilot_name":"Hewitt","damage_type":"1) RAF Bomber Losses","comments":"1) no comment."}To get this to work, fill in the field ID’s (e.g.
fld-prefixed items) and remove the/*and*/lines to actually create a new field in the link to form field. Might need some testing but you can see roughly what it’s doing.June 19, 2021 at 9:30 AM #44647In reply to: Split note field?
Sam Moffatt
ParticipantWithout actual data it’s a little hard to give you a solution but something like this should make sense.
let input = `Field 1 Field 2 Field 3, Field 4 Field 5 Field 6, Field 7, Field 8 Field 9 Field 10 Field 11 Field 12 Field 13 Field 14 Field 15 Field 16`; let lines = input.split("\n"); let fields = []; fields[1] = lines[0]; fields[2] = lines[1]; let line2Pieces = lines[2].match("([^,]*), (Field .*) (Field .*)"); fields[3] = line2Pieces[1]; fields[4] = line2Pieces[2]; fields[5] = line2Pieces[3]; let line3Pieces = lines[3].split(","); fields[6] = line3Pieces[0]; fields[7] = line3Pieces[1]; fields[8] = line3Pieces[2]; let line4Pieces = lines[4].match("(Field [0-9]*) (Field [0-9]*)"); fields[9] = line4Pieces[1]; fields[10] = line4Pieces[2]; fields[11] = lines[6]; fields[12] = lines[7]; fields[13] = lines[8]; fields[14] = lines[10]; fields[15] = lines[11]; fields[16] = lines[12]; console.log(fields);I’ve used an array to store the various fields in to show how that should look parsed out. Instead of using the array (e.g.
fields[1] = ...) you’d would directly set the field value (e.g.record.setFieldValue("fld-field1id", ...)).At a high level we split things by line, then for the lines that are purely comma separated we split them by the comma and then for the lines that are a mix, I’m using a regular expression to extract out the pieces. This is where knowing the actual form of the data would help because you can build a regular expression to capture the format.
For example a US formatted location could be parsed this way:
console.log("Cupertino, CA 95014".match(/([^,]*), (.*) ([0-9]*)/));June 19, 2021 at 2:47 AM #44645In reply to: Split note field?
Emil Mitchell
ParticipantThank you very much for your replies. That is great that such a script can be formatted. It will save a lot of time.
I have attached an example of how my data is formatted within the note field in question.
The individual parts of the data that I would like to split into their own field are marked “Field 1” to “Field 16”.
As you can see, some parts of the data are separated by commas, some are not, and some are separated by being on the next line.
Is it still possible to split the note?
Thank you!
Attachments:
You must be logged in to view attached files. -
AuthorSearch Results