Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
August 11, 2020 at 6:40 PM #41656
Topic: Question Concerning Script Folder Access
in forum Using Tap Forms 5Rocky Machado
ParticipantHi Brendan – The new feature you added on the preference UI. Can I access JSON files using the
Utils.getJsonFromUrlfunction? I was trying the following syntx, but it was not working for me. Could you send me a snipet of code on how to use this new feature?let response = Utils.getJsonFromUrl('/Users/alfredojmachado/Documents/sample.json') console.log(JSON.stringify(response,null,4));thanks,
rockyAugust 9, 2020 at 10:49 AM #41639In reply to: Is there a Roadmap?
Chris Ju
ParticipantHello Ting,
i’m using TapForms with many forms (which are linked), really many fields (many calculations and scripts) and about 30.000 entries. So far I haven’t had any problems with poor performance or with synchronization (CouchDB via Docker).
Cheers
ChrisAugust 8, 2020 at 1:41 AM #41615In reply to: Syncing again Mac, iPhone, iPad
Brendan
KeymasterThanks for the detailed description of the sync process Sam. Sam is exactly right in describing the challenges and the way sync works.
Sometimes things do get out of sync and one way to rectify that is to use the Send Document function to re-send another copy of the document over to your other devices. That assumes of course that you have a device which is the source of truth. It’s always best to have a single source of truth, such as Sam described with the star topology. The Mac is the source of truth and all the other devices sync to it.
If you don’t want to send the entire database over, you can also use the Export Tap Forms Archive command to generate a .tfarc file which you can import into another device. In that scenario, if there are changes or additions made to the form, records, fields, etc. then when you import, Tap Forms will apply those changes. It won’t delete anything though when importing a .tfarc file.
Sync is definitely a difficult thing to understand and to program. That’s why I initially chose CouchbaseLite as a database engine for Tap Forms 5. It contained within it the ability to sync using the CouchDB protocol and peer-to-peer syncing. So Tap Forms relies on that library to provide the syncing for those services. Cloudant also falls in that. Yes, IBM made it more difficult to setup, but it is possible and it does work, as long as you stay within their restrictions, such as records being less than 10 MB big (including attachments) and not storing more than 1 GB of data there.
And now Apple has thrown more curves at us developers by introducing the new Apple Silicon Macs and all the changes in Big Sur and iOS 14. So I’ve been focusing on making sure that I can get Tap Forms to run natively on Apple Silicon. I’m also investigating a new third-party sync engine framework which will hopefully allow me to bring back Dropbox syncing (as well as iCloud syncing) and possibly another sync service or two.
But this is a really big project for me, so it will take a while to build, then test, then fix, then test, and so on… until it’s ready.
Thanks,
Brendan
August 7, 2020 at 11:27 PM #41614In reply to: Syncing again Mac, iPhone, iPad
Sam Moffatt
ParticipantBento only ever supported syncing from a Mac to an iPad and it was manual sync as well. Though you’re going between two devices and you’re cognisant of having to do the sync otherwise your changes didn’t get to the other side. You had to be aware of it and explicitly do it though perhaps for some folk that would make it more explicit if the same behaviour occurred with Tap Forms.
Multi master sync is hard, especially when you factor in sync failures, devices that might be offline frequently and conflicting edits. My understanding is that Tap Forms automatically resolves the conflicts based on the last record edited. However that can still inadvertently lead to data loss if you edit a record on a device, realise that it’s out of sync and then trigger the sync you will loose data. Last write wins is a common resolution strategy. An alternative would be having to manually reconcile every change and perhaps that’s an improvement but that could in some situations lead to hundreds or thousands of records being out of sync (an updated calculation or script could easily trigger changes to records).
iCloud Sync seems consistently problematic which in part makes sense because it’s backed by Apple’s notoriously finicky platform. Even Apple’s own apps mess up iCloud so I’m not surprised that Tap Forms has some challenges with the platform too. I am more curious about the Nearby Sync and Cloudant failures though.
For Nearby Sync I found quirks at times when everything talked to everyone because you’re basically inviting a race condition to occur. I did have some weirdness at times in propagation that generally got solved by moving it to a star topology where Tap Forms on my iMac had every other device added to it and then every other device only had the iMac. Nearby Sync works on a pull basis when the app is open and only when you’re on the same network, so it is actually easy to open up the app, make changes and realise that your device is out of sync. Nearby Sync I think is great if your devices are at a single location and you can have one instance of Tap Forms (I use a Mac but you could use any device that runs Tap Forms) open consistently for everything to sync against. If you have multiple devices and they aren’t always running Tap Forms when the changes are made then you will end up with situations where devices don’t have all of the changes because Tap Forms needs to be on at the same time on those devices for nearby sync to work.
The Cloudant/CouchDB side should make that better because it’s a hosted server model. Instead of having one Tap Forms app open all of the time, there is a server that is always on. That said if you lose connectivity to that server, you can’t push the changes but offline editing will still happen. There are a few situations where I believe Tap Forms will pause sync indefinitely depending on the error it receives (e.g. unable to connect to the server), that could trip someone up who is expecting it to be working but not realising it hasn’t been. This is generally easy to triage: on the Mac if you look at the bottom right after you make a change the “last uploaded” time should update and if you make a change on another device last downloaded should change; those same timestamps exist on iOS on the Tools tab.
Hopefully that helps folk out and make sync a little more reliable.
August 7, 2020 at 11:12 PM #41609In reply to: Getting field script to work
Sam Moffatt
ParticipantThe reason it doesn’t autoupdate is because you’re obscuring the field ID’s and Tap Forms doesn’t know which field to watch. If you pull down on the record to recalculate the fields, it should update. Tap Forms is coded to look for the two placeholder templates and will use that to setup the links when those fields are changed.
In the script editor, there is a button at the bottom that will let you open a field list:

In this field list you’re given two options at the top, I’d go for the left one and then tap on the field you want. The right one will work but for this simple use case, I’d personally pick the left one:

That will put the
getFieldValuecall directly into your script and you can use it from there:
In your case it should simplify your script down to about three lines inside the function to just directly retrieve the field values and return their multiplied value.
Attachments:
You must be logged in to view attached files.August 6, 2020 at 10:31 PM #41607In reply to: Getting field script to work
Nigel Hughes
ParticipantHi Sam,
Thanks so much for responding. However still the value of the Number3 field in the record is not changing when the Number1/2 fields are changed. Just for clarity my code now is:
function Number3() {var Number1_field = form.getFieldNamed(‘Number1’);
var Number2_field = form.getFieldNamed(‘Number2’);
var Number1_ID = Number1_field.getId();
var Number2_ID = Number2_field.getId();
var Number1 = record.getFieldValue(Number1_ID);
var Number2 = record.getFieldValue(Number2_ID);var Number3 = Number1 * Number2;
return Number3;
}Number3();
(I changed the the expected value of the Number3 script field to be a number.) Any other ideas?
Thanks again …
August 6, 2020 at 6:14 PM #41600Topic: Getting field script to work
in forum Script TalkNigel Hughes
ParticipantHi,
I’m trying to get field scripts to work (on iOS) and having little success. To simplify things I’ve copied some code from https://www.tapforms.com/help-mac/5.3/en/topic/scripts but can’t get it to output anything (when Number1/2 is changed). The exact code I’ve entered for the Number3 script field is:
function Number3() {
var Number1_field = form.getFieldNamed(‘Number1’);
var Number2_field = form.getFieldNamed(‘Number2’);
var Number1_ID = Number1_field.getId();
var Number2_ID = Number2_field.getId();
var Number1 = record.getFieldValue(Number1_ID);
var Number2 = record.getFieldValue(Number2_ID);var Number3 = Number1 * Number2;
‘The total is: ‘ + Number3;
form.saveAllChanges();
}Number3();
I’ve attached a screenshot of the form setup. Can anyone help me to get Number3 to change its value based on Number1/2?
Thanks alot.Attachments:
You must be logged in to view attached files.August 6, 2020 at 2:22 PM #41599In reply to: Question about Future Releases
Rocky Machado
ParticipantHi Brendan – Sorry I missed your response. I’m actually looking for a container that would allow me to run a widget. For example, this TradeView widget is something I would put in the Tapform Layout interface. Here is a snippet of the embed code Anyway, I thought I would ask.
<!-- TradingView Widget BEGIN --> <div class="tradingview-widget-container"> <div id="tradingview_e1957"></div> <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-AAPL/" rel="noopener" target="_blank"><span class="blue-text">AAPL Chart</span></a> by TradingView</div> https://s3.tradingview.com/tv.js <script type="text/javascript"> new TradingView.widget( { "width": 980, "height": 610, "symbol": "NASDAQ:AAPL", "interval": "D", "timezone": "Etc/UTC", "theme": "light", "style": "1", "locale": "en", "toolbar_bg": "#f1f3f6", "enable_publishing": false, "allow_symbol_change": true, "container_id": "tradingview_e1957" } ); </script> </div> <!-- TradingView Widget END -->August 5, 2020 at 11:52 PM #41597In reply to: Display contents of field in a linked db
Vincent Nunez
ParticipantHi Sir Moffat – I do appreciate your time and your complete reply. Thanks to your emphasis on that ‘child records loop’ snippet, and thanks to all the tutorials available through the website here, I took a more patient look and Approach #1 is now working for what I need at this time. Honestly it’s been awhile since I last hacked about with scripts. I didn’t realize how (relatively) easy Tap Forms was making it for me. I’ll keep at it! – Respectfully, Vincent
August 5, 2020 at 12:37 AM #41591In reply to: Display contents of field in a linked db
Sam Moffatt
ParticipantA JOIN field is a many to many relationship, you need to iterate over the values. For Approach #1, use the ‘child records loop’ snippet with the field you are interested in and it will put the rest of the loop scaffolding in for you. You will have to choose what you do from there, merge everything together, return the first one you see or something in the middle.
I’m not sure why Approach #2 isn’t working, though I’ve not used that syntax and I suspect the JOIN link messes with it as well for similar reasons to Attempt #3.
The JOIN type’s many to many relationship is why Attempt #3 with the calculation field is giving you issues because there could be more than one record linked, so it defaults to giving you a count because the calculation tool doesn’t have the depth to let you handle multiple values.
If this is supposed to be a singular value, I’d recommend creating a Link to Form in your other form as 1:M and then ticking show inverse relationship. It’ll create a Link From Form field in your current form which will simplify Attempt #1 and Attempt #3 will let you pick the individual fields.
If using the Link From Form doesn’t get you across the line you can also have the scripting create the CSV for you and then copy it to the pasteboard (not recommended for terribly large amounts of data but a few MB of data shouldn’t stress it too much). Then you’d run a form script to populate your pasteboard and you can paste it into a destination app or TextEdit to save to disk.
August 4, 2020 at 11:03 PM #41589In reply to: Display contents of field in a linked db
Vincent Nunez
ParticipantAny further developments here?
I want to lookup values in an external table. I am joining the two tables by matching with fields both tables have in common. I *believe* these are properly linked with a Join field. But my external table does not seem to be returning values no matter what I try. The external table’s fields do appear to be available. Yet are they really?..
Approach #1 — I attempt to use a script field. I get the ‘ReferenceError: Can’t find variable’ error. (I am wondering, why would I have an index to iterate with when I am using a field-level script? I pull from a source, I assign a waiting destination field – yet nothing goes through. I can run the script with local table information, no problem.)
Approach #2 – I attempt to use “mail merge” syntax like so – [ExternalTable::JoinedField]. But this does not update when printed (to PDF). Local merge fields are updating (when out to PDF) no problem.
Approach #3 – I attempt to use a calculation field as text output. But when I try to use any of the external table values I only seem to be able to access them through Count operation. I want to access a string, not a count of values.
Approach #4 – Almost forgot. The closest I have gotten was actually my first attempt of embedding my external lookup into a plain layout. I am able to export that out as hardcopy, yet what I need is a reliable CSV export, not a copy/pasting activity based on PDFs. (Approach #2 would be ideal..)
What basic ideas am I missing?
Thanks,
VincentJuly 30, 2020 at 9:21 PM #41576In reply to: Tap Forms Javascript Scripting 101
Brendan
KeymasterDone!
https://www.tapforms.com/help-mac/5.3/en/topic/scripts
The second blue banner box on the above page has a link to your tutorial.
Thanks!
July 30, 2020 at 5:20 PM #41575In reply to: Tap Forms Javascript Scripting 101
T.L. Ford
ParticipantI’d be honored if you’d link it in your Scripting documentation.
– T
July 30, 2020 at 12:35 PM #41574In reply to: Tap Forms Javascript Scripting 101
Brendan
KeymasterThis is awesome!
Do you mind if I put a link to your tutorial in my Scripting documentation?
Thanks!
Brendan
July 29, 2020 at 7:22 PM #41567In reply to: Tap Forms Javascript Scripting 101
Sam Moffatt
ParticipantJavascript’s Array has a lot of fun stuff in them to make use of interesting properties, another example is
mapwhich lets you apply a closure to every item automatically andfilterwhich can remove elements from an array.forEachis another useful one to use plusfor (x of y)andfor (x in y)syntax for iteration.Here’s the same method rewritten to use
mapto extract the chore name and update some state and thenfilterto remove the empty array elements (not exactly a good use case as we’re essentially usingmapas a for loop or forEach construct):function Chore_Report() { let current_chores = []; let done_count = 0; let chores = 0; current_chores = record.getFieldValue('fld-08db542d325b434faea0d99cec89e1c9').map(rec => { let done = rec.getFieldValue('fld-0dba6e502e1e4151ab34d9d8afa2cd19'); chores++; if (done) { done_count++; return undefined; } else { return rec.getFieldValue('fld-2c5a9c565a7c480680659d1664daae3e'); } }).filter(chore => { return chore !== undefined }); var report = "Chores total: " + chores + ", Done: " + done_count + "\n" + current_chores.join(", "); console.log(report); return report; } Chore_Report();To be honest I think purely correct or efficient at times isn’t as educational because there isn’t always a journey, things breaking, seeing issues as they arise and then fixing them. We learn more by the mistakes than by perfection or at the very least seeing how to overcome mistakes is useful when you run into your own issues.
Also I’m loathe to reboot though there is something screwy with the GPU in my MBP so every so often I get a kernel panic to reset things.
Look forward to seeing where to from here once you get some more time :)
-
AuthorSearch Results