Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
August 26, 2019 at 3:11 PM #36523
In reply to: multiple horizontal objects in list
Sam Moffatt
ParticipantYou can do the same on the iOS version as on the Mac, in the calculation editor you need to use
[Field Name]instead of clicking on the fields and also you need to make sure you use the quote button above the keyboard to avoid inserting smart quotes.The examples above in the iOS calculation editor would be
CONCAT([First Name];" ";[Last Name])andCONCAT([Street];" ";[City];" ";[State]).Doing the script example on iOS is a few extra taps to select the fields but not that bad. I prefer script fields because of the better error reporting and testability (just click the “run” button to see if the field will work; make sure you’re on a record first though or you’ll get an error that
recordisn’t defined or similar). I wouldn’t want to do a lot of script or calculation field work on iPhone but on the iPad it isn’t too bad if you have a full keyboard. I’ve written some pretty crazy stuff on the phone but doing it on the desktop and using P2P sync or CouchDB sync is much easier.Attached is a video of doing a new script field on my iPhone in one of my test databases, reordering it to make sure it’s the first and then going to the list view on the phone.
Attachments:
You must be logged in to view attached files.August 26, 2019 at 2:04 PM #36522In reply to: Re class a field typer after script. (Web Location)
Sam Moffatt
ParticipantYou can’t make a script field clickable (would be nice, it’s on my wish list*) however as a workaround what you can do is use the script field to set the value of a web site field using
record.setFieldValue(field_id, value). Then when the script is run, it’ll update the web site field to be the new value which means you can then click on that field to open the link.* I’d actually like a way of being able to define a custom icon for a script field and an action handler distinct from value. I think it’d be cool to have the ability to have the script field display one value but when you click it, it opens up a link or perhaps even runs a form script with a
fieldcontext set. Doing all of that and getting it right is a lot of work and perhaps a little too powerful.August 26, 2019 at 1:55 PM #36520Sam Moffatt
ParticipantTry something like this:
var address_id = 'fld-fb97220d3a4a4df48df4a54030766c54'; record.getFieldValue(address_id).match(/Cupertino/) ? 'Yes' : 'No';You can use the method
matchon strings, it takes a regular expression which is why the string is in backslashes not quotes. I use a ternary operator to take the output of the match and do a ‘yes’ or ‘no’ based on if something was found.W3C Schools page for match: https://www.w3schools.com/jsref/jsref_match.asp (has links for further details on regular expressions)
Mozilla page on ternary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_OperatorAugust 26, 2019 at 1:24 PM #36515In reply to: multiple horizontal objects in list
Sam Moffatt
ParticipantCreate a new calculation field, in the form options you can set it up. Here’s a quick recording of how do that with a calculation field.
Looks like I hit a bug/quirk that commas, even in the quoted strings, seem to trigger something. That one’s for Brendan to look at.
To work around that, I also did a similar example using a script field. It’s a little more verbose but I find the script fields easier to work with than the calculation fields because it has better error reporting (easier to know what you did wrong). That’s probably less likely if you don’t learn JavaScript but there are plenty of resources on the web to learn JavaScript.
As you can see, both of the calculation fields update the list view on the left to display the composite data. Hopefully this helps!
Edit: Had to trim the calculation field recording to get it to fit under the file size limit. I attached a screenshot of what the final calculation that worked looked like (I ended up doing some experimenting with field separators).
Attachments:
You must be logged in to view attached files.August 26, 2019 at 6:29 AM #36512Topic: Re class a field typer after script. (Web Location)
in forum Script Talkmatt coxon
ParticipantHi, I’m using the vlookup script by (Sam Moffatt) great script thank you Sam!!!
Is there a way to make a script field be a clickable URL / Hyperlink (as it would be if you had selected the “Web Site” field
This is the script,
Thanks Matt
form.runScriptNamed(‘vlookup’);
var trello_cards_id = ‘fld-a6346935a6af40d1833fad4f49958bca’;
var tsm_rfs_id = ‘fld-b0c9111f87064a23bde75c965374e97c’;
var short_url_id = ‘fld-7888517ad8204f5aa7a4bf926c92be15’;var rfs = record.getFieldValue(‘fld-e13aa1493c6f4b919f30b27cd8bc8ae9’);
vlookup(rfs, trello_cards_id, tsm_rfs_id, short_url_id);
August 26, 2019 at 5:54 AM #36509Topic: Script to search for specific string in a a records field
in forum Script Talkmatt coxon
ParticipantHi, im playing around with scripts, (i’m new to them) is there a way to search a field for a partiular string and the output accordingly
Example would be
Field “Labels” has the following text (urgent,storage,emea,network,office moves,colo,new)
I’d like the script to search for the string “office moves” and return either a “yes” or whatever Id like
Is that possible
ThanksAugust 25, 2019 at 2:31 AM #36481In reply to: multiple horizontal objects in list
Brendan
KeymasterYou could simulate that with a Calculation or Script field to concatenate the values.
August 20, 2019 at 6:55 PM #36416In reply to: Need an example code to SUM checkboxes
Sam Moffatt
ParticipantOk, I’m going to attach a form template for this as well but the gist is naming a bunch of checkboxes the same way and then managing their state.
Two sets of checkboxes, one named “CBA” then a number and another set named “CBB” then a number. I created 15 of the CBA and 4 of the CBB. Too easy.
The biggest challenge in this is managing all of the checkbox ID’s because clicking all of those is a pain. Step 1: Form Script to generate Javascript for later (I called this “Generate Checkbox Script” but you could call it something else):
var fields = form.getFields(); console.log(`var cbaList = [];`); console.log(`var cbaValues = [];`); console.log(`var cbbList = [];`); for (var index = 0; index < fields.length; index++) { if (fields[index].name.match(/CBA/)) { console.log(`cbaList.push('${fields[index].getID()}');`); console.log(`cbaValues.push(record.getFieldValue('${fields[index].getID()}'));`); } if (fields[index].name.match(/CBB/)) { console.log(`cbbList.push('${fields[index].getID()}');`); } }This is an abuse of
console.logbut essentially I’m using it to write Javascript code. What we’re doing is asking the form for all of it’s fields (form.getFields()) and then looking to see which ones matchCBAand which ones matchCBB. TheCBAones we want to track their state, so we put the field ID into a list and then also grab their value at the same time. ForCBB, we don’t necessarily care about it’s values until we know that all of CBA has been ticked, so we don’t bother with the extra lines. That for my template generates this:var cbaList = []; var cbaValues = []; var cbbList = []; cbaList.push('fld-955441d1635b4ce399a4d6008c7ee37d'); cbaValues.push(record.getFieldValue('fld-955441d1635b4ce399a4d6008c7ee37d')); cbaList.push('fld-b22653c0a9904dcd976c31e8ba0388fe'); cbaValues.push(record.getFieldValue('fld-b22653c0a9904dcd976c31e8ba0388fe')); cbaList.push('fld-49d779446f6b42a897a11d137e1c2817'); cbaValues.push(record.getFieldValue('fld-49d779446f6b42a897a11d137e1c2817')); cbaList.push('fld-308e12249c64487fae2237f325fbc21d'); cbaValues.push(record.getFieldValue('fld-308e12249c64487fae2237f325fbc21d')); cbaList.push('fld-99ade950b34c4d53bd98c218dce8d8ef'); cbaValues.push(record.getFieldValue('fld-99ade950b34c4d53bd98c218dce8d8ef')); cbaList.push('fld-617fcf4b482e44cf92eac93d4719b2c9'); cbaValues.push(record.getFieldValue('fld-617fcf4b482e44cf92eac93d4719b2c9')); cbaList.push('fld-3c97916b19f049bbb7edf6a2c68d0e3a'); cbaValues.push(record.getFieldValue('fld-3c97916b19f049bbb7edf6a2c68d0e3a')); cbaList.push('fld-fc1d9f241ac745119901b4e1cabaab7b'); cbaValues.push(record.getFieldValue('fld-fc1d9f241ac745119901b4e1cabaab7b')); cbaList.push('fld-2beae294572d40178c5f31b39d9d2f3e'); cbaValues.push(record.getFieldValue('fld-2beae294572d40178c5f31b39d9d2f3e')); cbaList.push('fld-53b3172d013343eaa510169e71cc1a15'); cbaValues.push(record.getFieldValue('fld-53b3172d013343eaa510169e71cc1a15')); cbaList.push('fld-880186ebe46e49cea5e2fa487e0112dc'); cbaValues.push(record.getFieldValue('fld-880186ebe46e49cea5e2fa487e0112dc')); cbaList.push('fld-3c644b46b5b64f5e80575c601ef86938'); cbaValues.push(record.getFieldValue('fld-3c644b46b5b64f5e80575c601ef86938')); cbaList.push('fld-1c85ce9ada1643ac89eb3304fffdb730'); cbaValues.push(record.getFieldValue('fld-1c85ce9ada1643ac89eb3304fffdb730')); cbaList.push('fld-614d0018122d4a8eab464f96a3a4a623'); cbaValues.push(record.getFieldValue('fld-614d0018122d4a8eab464f96a3a4a623')); cbaList.push('fld-16d97ccc160b4d26b572e38c89633908'); cbaValues.push(record.getFieldValue('fld-16d97ccc160b4d26b572e38c89633908')); cbbList.push('fld-2437b06a3d3c4646a11c093e260fe860'); cbbList.push('fld-b465ee9958c44acdab05ceb042bc582e'); cbbList.push('fld-5fa2c5b939354661b706ba35a55fabc8'); cbbList.push('fld-1748eee5b1eb42f19fab7e74431a2710');The three lists (cbaList, cbaValues and cbbList) end up forming the basis of the next piece. I pasted that into a new field script replacing it’s contents (I called mine “Checkbox Watcher” but really you can name it what you want).
I then wrote some stuff! Let’s take it apart, piece by piece:
var setFlag = 0; var result = 1;Setting up our variables:
setFlagis used to know if I set a field andresultis used to see if all of the checkboxes have been checked.for (var cba = 0; cba < cbaValues.length; cba++) { result = result & cbaValues[cba]; }This is a simple loop over all of the
CBAfield values and it does a logical AND operation on each of them againstresultwe created before. If any of them are zero/false, then result will be false and zero out for the rest of the runs. If they’re all set to one, then they’ll all come together. This means that the script will work on an arbitrary number of checkboxes without having to know precisely how many checkboxes there are.if (result) { for (var cbb = 0; cbb < cbbList.length; cbb++) { console.log(`${cbbList[cbb]}: ${record.getFieldValue(cbbList[cbb])}`); if (!record.getFieldValue(cbbList[cbb])) { setFlag = 1; record.setFieldValue(cbbList[cbb], 1); document.saveAllChanges(); break; } } }First bit of fun, if we have all of the checkboxes checked, look for a checkbox from
CBBthat hasn’t been checked and check it. When it’s checked,setFlagis toggled for the next chunk.document.saveAllChanges()is sprinkled in to make sure to tell TapForms to persist our changes.if (setFlag) { for (var cba = 0; cba < cbaList.length; cba++) { record.setFieldValue(cbaList[cba], 0, false); } document.saveAllChanges(); }If
setFlagwas set, then this loops through all of theCBAcheckboxes and sets them to zero. There’s a third flag tosetFieldValuehere which is set tofalse. This is a special flag that tells TapForms to *not* trigger script changes which would call this script again and cause it to loop. More saving of changes too!document.saveAllChanges(); console.log(new Date()); console.log(`All checked? ${result}`); console.log(`Did we set overflow? ${setFlag}`); `${result}/${setFlag} @ ${new Date()}`;For good measure I have a final
saveAllChangesthat really is there from when I first started the script. I log out some debugging messages starting with a date, if all of the checkboxes were checked, if this invocation of the script set the overflow and then it sets the script field value to a slightly formatted form for easy reviewing.Gotchas
I didn’t test this on iOS but it should work fine there as well.
When you import the template, open up the “field script” and save it. This should force Tap Forms to set up the watching behaviour properly. For me when I did a quick test import, that didn’t work properly however editing the field and saving it worked properly.
The last gotcha I found with this was that on the Mac, the UI didn’t seem to update properly after the last checkbox was checked. Since I’m uploading this template, hopefully the keymaster can have a look and see what’s up there. If I navigate away from the record to another one and then return, the checkbox state is correct. If I click on “recalculate formulas”, it refreshes the UI properly.
Why the form script and the field script?
A fine question is why I even write Javascript to write Javascript at all, couldn’t I just run the same Javascript directly? And the answer to that question is actually yes! I could have a field script that handled the same logic as the form script and it would mostly work. The only requirement would be to press the “recalculate formulas” to trigger the field script to run. For TapForms to trigger updates to a field script automatically, it needs to know which fields to ‘watch’. TapForms has some heuristics it runs to figure that out but the simplest is looking for
getFieldValue('fld-id'). The point of the form script is to write the Javascript we need to get TapForms to watch the fields (in this case the 15 checkboxes) we care about. It’s also another reason why we don’t get the values of theCBBcheckboxes that way: we don’t want to get updates for these fields, so we avoid triggering that behaviour.This particular behaviour is on the edge of magic for me. I’ve made my peace with it because it mostly works and it is easy enough to work with or around once you understand it.
Attachments:
You must be logged in to view attached files.August 20, 2019 at 5:42 PM #36414In reply to: applescript support and open local files
Bert Rietveld
ParticipantThanks, Brendan. Waiting then (impatiently) for the next update ;)
I’ll continue my workaround for now: Copy the URL to the clipboard and running a fastscript or using keyboard maestro.August 20, 2019 at 12:59 PM #36408In reply to: Need an example code to SUM checkboxes
Sam Moffatt
ParticipantA straight forward implementation would likely be if/else but I’ve been thinking about the checkbox use case with some sort of array to do a for loop. I think it might be achievable with some introspection but it hasn’t quite come to me yet.
Everything will work on iOS except for the custom layouts. Running the scripts on iOS is a few more taps.
August 20, 2019 at 12:46 PM #36407In reply to: applescript support and open local files
Sam Moffatt
ParticipantI don’t think this is a scripting limitation, this is a MacOS App Store sandbox limitation. App Store apps can only access files in its sandbox or files that you have used the Apple file dialog to select.
Are you using the App Store version? I thought at one point there was a stand-alone version that might not have the same limitation (perhaps try the trial version?).
August 20, 2019 at 9:42 AM #36406Topic: applescript support and open local files
in forum Script TalkBert Rietveld
ParticipantJavascript support is a great addition to Tap Forms, but has some limitations (for good safety reasons): It cannot open local files. Unless I’m missing something, it cannot trigger an AppleScript (which could open local files). Putting a local file URL in a website field results in “Tap Forms Mac 5” does not have permission to open…”. Dropbox file URLs work but I cannot move everything over to Dropbox (>2TB). Some mechanism to script a button to get to local files would be very good. Does anybody know of a way how to do this?
August 20, 2019 at 6:58 AM #36405In reply to: Need an example code to SUM checkboxes
Karl M. Rowe
ParticipantHi, Sam!
Thanks for working up and posting this script for me. I especially liked what you did here:
“The ‘Customers’ form has a bunch of stuff in it. I added a photo and title field for fun then we get into the more interesting business.”
Having a photo field would be great!
“Downside of this is that it only works on the Mac.“
So it’s possible that I may encounter one or more issues since I using the Tap Forms app on the iPad, but there is much here in the code you posted to study. Thanks for attaching the link to a zip file. As long as the files don’t require a Mac, I’ll probably be able to make use them.
I would really be interested in seeing some code that deals with checkboxes. Here’s that example I had in mind again:
Let’s say in a form you had the Checkboxes A!..A3 snd Checkboxes B1..B3, and when CBB1 and/or CBB2 and/or CBB3 is/are set to “1” (checked), then the CBA1, CBA2 and CBA3 checkboxes would be reset to “0” (unchecked), and only if CBB1 was set to “1” would the corresponding CBA1 would to set to “1” and CBB1 would be set to “0”; only if CBB2 was set to “1” would the corresponding CBA2 would to set to “1” and CBB2 would be set to “0”; and only if CBB3 was set to “1” would the corresponding CBA3 would to set to “1” and CBB3 would be set to “0.”
What would such code look like? Would you use a “IF/ELSE” or a “FOR” loop to do this or something else altogether?
Thanks again, Sam.
Peace
August 20, 2019 at 6:42 AM #36404In reply to: Need an example code to SUM checkboxes
Karl M. Rowe
ParticipantHi, Brenden!
“Did you get any syntax errors when running your script in the Script Editor?
“Make sure you don’t use curly quotes or curly apostrophes. That can cause things to fail.”
Ok. Thanks; I will be careful to use straight quotes and check that within that which I may paste into one of my test scripts do not contain curly quotes.
Peace
August 20, 2019 at 3:12 AM #36397In reply to: Anyone here that can build a database for pay?
D J Leason
Participant@ Sam Moffatt
Ok so when I first started building the forms, I just did it in the sample form document so I could see the examples. Then I copied my stuff to a separate document. It looks like some of the forms are duplicates, that’s why. Some of that stuff in there like My Movie collection either came in the original TF template download or other templates I got off of the forum. You should be able to tell which forms have to do with herbs. This is not one of my forms:– First Name (fld-9d1bca52fb894f75a01b29fbd789d198)
– Last Name (fld-051eefffbb93476e9e9d65d149641169)
‘Contact’ contact (fld-62e52ae50ee5413abb2f5016d7227183)
‘Website’ web_site (fld-0ca041e8f0974c7ba736d0823010978f)
‘First Name’ text (fld-9d1bca52fb894f75a01b29fbd789d198)
‘Last Name’ text (fld-051eefffbb93476e9e9d65d149641169)
‘Phone Number’ phone (fld-c84e74d1fac64a57b0bdce5b79cc8e3d)
‘Email Address’ email (fld-c05386d884b941808a6822584ca1b642)
‘Street Address’ text (fld-3bbf50e5c9164a2986876229374c8b88)
‘City’ text (fld-fac7bf008a954d5e8bc5354fba68de5d)
‘Province’ text (fld-96389320949f4925a201e85a3452fe79)
‘Postal Code’ text (fld-b97c9408b6d34214bc3778f00c29e59f)
‘Country’ text (fld-5e691c9792bb488594b336ba1ae52c29)
‘Client Documents’ file (fld-3d142c97df914bbeb5671d7e0e1110cb)
‘Client Call Log’ form (fld-01144d1c706e4007a7ad1a7c98fe9147) toMany ‘Client Call Log’ (frm-581dd7a1772345f2af2724c80fa1155b)This is not my form:Daily Journal: (frm-494dc8cef1934c0393dc932d13ccd94a)
‘Date’ date (fld-bf50f76f8fbe417faf8ae9e627972546)
‘Action’ text (fld-c0cae13ad58546b0a5023cd9d9984815)
‘Journal Entry’ note (fld-3849af82aa3e4304b3fb42441841b3ec)This is not mine:=== ‘Movie Details’ section (fld-a0d18fb6afa040b59e01bc4ed8bbc811) ===
‘Genre’ text (fld-2a0d16d2aece4562b6f44170cf1736a6)
‘Summary’ note (fld-28cc8f7f082c43818f1169c96c96e5a9)
‘Rating’ rating (fld-3baff54c8e164de9b9ad3f0fbb040bc6)
‘Year Released’ text (fld-3a365169f48a4b69ad37e86e171f0e00)
‘I Watched This’ check_mark (fld-5fda15d66484465da69196949f1b9353)
‘Actor/Actress 2’ text (fld-4cacb0cf58364eb091437ac1834a4862)
‘Actor/Actress 3’ text (fld-2cdb0cf1ef1743b68fa5bda36f694a08)
‘Directed By’ text (fld-522a5de85bcc44e087e473bb2567a471)
‘IMDB Website’ web_site (fld-9bc90613e8db45fea77579f35eb53b9d)Home Inventory: (frm-5de3dd00a2b44d4b802166979c21f91b)
‘Picture’ photo (fld-294fa505e27c4aa99438339d59c1b40d)
‘Purchased From’ text (fld-2d3154a342914146a6d7cbb8659527fa)
‘Insured Value’ number (fld-3e3c56a2b59d401fba379b508a54e3f2)
‘Number of Items’ number (fld-49afd76a3770426db95569493d17ff87)
‘Received as Gift’ check_mark (fld-57d6f4e4d3cf4e57a9b6f56b9f3bfd51)
‘Serial Number’ text (fld-58095db96d1d4f1c9ca0b1ede05e2802)
‘Purchase Date’ date (fld-5c45c558205e4989836e218b7e2863de)
‘Original Cost’ number (fld-6dbd8f48549a44529d58d9167d2ae142)
‘Location’ text (fld-880ae556bea942e1891b21ca46c582da)
‘Notes’ note (fld-92fa01ec5f5b4204b15695fb00df89c3)
‘Category’ text (fld-9ee801f49a884f9484235d3d4181694d)
‘Purchased Warranty’ check_mark (fld-a5061f32941641e2a89ca68ce172daf1)
‘Condition’ text (fld-b2dc1cf3e0554c1790a80fb1f3b16bce)
‘Item’ text (fld-bffefe6a2a6e4167a680479de15d62a3)
‘Description’ note (fld-da04516482fc48138a2b509394e08962)
‘Current Value’ number (fld-ef1ecf1eaff44d3bbbd0246fdbf8653f)Or this:
Expenses: (frm-8bff4863a7594cbb8938e0b433ef5efb)
‘Description’ note (fld-e90e747b90dc49c1be7d2c02f07af3bc)
‘Expense Type’ text (fld-5a7a671218d84096847d1732cd214d88)
‘Amount’ number (fld-3da10ad6c3d7445a817fc132162f5937)
‘Date’ date (fld-edb6e5c684c74325a33892af25f42d8c)
‘Have Receipt’ check_mark (fld-b2f71831e8bb4c72913571a762d3baa2)
‘Reimbursed’ check_mark (fld-2310439013c74c598d0711d44ee8efab)
‘Person to Reimburse’ text (fld-de1917d9ba0a4a0d8366815534693890)
‘Paid By’ text (fld-759bcedc78564c649c2f3af957a7750c)
‘Project’ text (fld-c6b48015180948bf9c0e41a58ef1d162)
‘Receipt Photo’ photo (fld-f11218ec5d774ce48d6a293e8b3917e4)
Clients: (frm-0ad8c86d89d04d91873f8a31f4dae2d7)
‘Company’ text (fld-1dd431ab21cb43d28967d1ebb36c23fa)
‘Full Name’ calc (fld-f86ccf72fcf848669d17db555ca697f3)Or this:
Referenced Fields:
– First Name (fld-9d1bca52fb894f75a01b29fbd789d198)
– Last Name (fld-051eefffbb93476e9e9d65d149641169)
‘Contact’ contact (fld-62e52ae50ee5413abb2f5016d7227183)
‘Website’ web_site (fld-0ca041e8f0974c7ba736d0823010978f)
‘First Name’ text (fld-9d1bca52fb894f75a01b29fbd789d198)
‘Last Name’ text (fld-051eefffbb93476e9e9d65d149641169)
‘Phone Number’ phone (fld-c84e74d1fac64a57b0bdce5b79cc8e3d)
‘Email Address’ email (fld-c05386d884b941808a6822584ca1b642)
‘Street Address’ text (fld-3bbf50e5c9164a2986876229374c8b88)
‘City’ text (fld-fac7bf008a954d5e8bc5354fba68de5d)
‘Province’ text (fld-96389320949f4925a201e85a3452fe79)
‘Postal Code’ text (fld-b97c9408b6d34214bc3778f00c29e59f)
‘Country’ text (fld-5e691c9792bb488594b336ba1ae52c29)
‘Client Documents’ file (fld-3d142c97df914bbeb5671d7e0e1110cb)
‘Client Call Log’ form (fld-01144d1c706e4007a7ad1a7c98fe9147) toMany ‘Client Call Log’ (frm-581dd7a1772345f2af2724c80fa1155b) -
AuthorSearch Results