Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
December 13, 2020 at 9:10 PM #42842
In reply to: Adv Find & Replace not working
Brendan
KeymasterHi Chris,
You’re right. It’s not working right for checkmark field types. I’m working on fixing that. In fact, I just fixed it (for the next update).
In the meantime, you can write a Form Script to accomplish the same thing that loops through the records, looking for the checkmark field value and turning it off if it’s on.
Are you familiar with scripts in Tap Forms yet? Here’s a sample bit of code that will do that for you, but you’d have to put your own Checkmark field’s ID in it:
function Toggle_Checkmark() { var records = form.getRecords(); var check_mark_id = 'fld-f14ccd51913b4348b2c32d9ac4eaf7f2'; for (var index = 0, count = records.length; index < count; index++){ // do something; var record = records[index]; var value = record.getFieldValue(check_mark_id); if (value == true) { record.setFieldValue(check_mark_id, 0); } } form.saveAllChanges(); } Toggle_Checkmark();Thanks,
Brendan
December 13, 2020 at 8:54 PM #42841Sam Moffatt
ParticipantIf you were to aim to optimise the script, I’d probably want to have a map of PDF name to Tap Forms record ID. You can do a retrieve of a record by key/record ID via the script so if you precomputed a map of these keys or used the record ID import mode for Tap Forms to import the records then it’ll be a single retrieve for retrieving the record (
form_record_idis the field in the CSV file which if present will be prepended with arec-prefix and allow you to useform.getRecordWithId). The horse has likely already bolted for this one but something to consider for future projects, so let’s go ahead with the other suggestion: PDF attachment name in a script field.If you have the PDF attachment name in a script field, you could use the
getRecordFromFormWithKeyfunction in my script manager. The method signature looks like this:getRecordFromFormWithKey(formName, keyFieldId, keyValue, createIfMissing = true, earlyTermination = true, alwaysScanOnMiss = false)It creates in Javascript an index on a first pass and then does looks up from there (set
earlyTerminationtofalseandalwaysScanOnMisstotrue). When you’re in a tight loop this should improve performance by doing the record loop once to build the index and then you can do a similar sort of roughly constant time retrieval for matching records. It’s still two loops but you remove the nesting and replace it with a more optimised data structure.First step is to create a new script field in your Contracts form and in it you want to add in the code we use to grab the filename from the PDF:
record.getFieldValue('fld-e870153bd0a647c9823ca998c213d1fd')[0].filename;You’ll need to tick the “Update records when saving” option when creating that to populate the new field in all of your record. Essentially we’re just copying the filename as a new field. At this point you might also want to setup a search to look for records that have this field empty because that seems likely a bug. You’ll also need the field ID from the form panel (underneath the “Description” field) which I refer to later as “fld-scriptfieldidhere” that you’ll need to change.
Using the code you provided as a basis, something like this should get you some of the way there:
document.getFormNamed('Script Manager').runScriptNamed('getRecordFromFormWithKey'); function Update_Records() { var csvForm = document.getFormNamed("csv"); // Contracts var keyword_id = 'fld-a2126cbe512646e9ba144fb5a90b06dc'; var pdf_id = 'fld-3ea77ccc18604174b722ece105965c44'; // get use fixed field Id var csvPdf_id = 'fld-4bcd0f1fba5c4178bb8d10a112b17489'; var csvKeyword_id = cvsForm.getFieldNamed('Keyword').getId(); // Loop over all csv entries for (entry of csvForm.getRecords()) { // get pdf file name of CSV record var csvPdfName = entry.getFieldValue(csvPdf_id); // replace spaces with underscores csvPdfName = csvPdfName.replace('/ /g', '_'); console.log("Processing: " + csvPdfName); contract = getRecordFromFormWithKey("Contracts", "fld-scriptfieldidhere", csvPdfName, false, false, true); if (!contract) { console.log('Unable to find matching PDF record: ' + csvPdfName); continue; } console.log("Found match: " + csvPdfName); // Update contract record var type_of_agreement_id = 'fld-6af499ed439143b297828643341d939b' contract.setFieldValue(type_of_agreement, 'Licensing Agreement') // This should “replace” keyword or keywords in a selected record var agreement_keywords_id = 'fld-a2126cbe512646e9ba144fb5a90b06dc'; contract.setFieldValue(agreement_keywords_id, entry.getFieldValue(csvKeyword_id)); } document.saveAllChanges(); return 'done'; } Update_Records();We’ve still got the outer loop that iterates over the incoming CSV form, the “Contracts” loop is removed and replaced with the call to
getRecordsFromFormWithKeywhich internally does a loop for you but also builds an index in memory that should make subsequent accesses quicker. Watch your memory usage in Activity Monitor but you’ve got 64GB of RAM so we should be fine. The script is finding the record for you so the code that lived inside your inner for loop moves up a level though there is a check to see if we got a record back. I did some minor changes to set the keyword based on the CSV form as an example of how I think that to work.One thing I’ve done in scripts like this is put in a field for when it was processed to be able to skip it and also a counter to limit how many records are processed. This is useful for debugging scripts and being able to progressively execute it to get an idea of it:
let minTime = new Date().getTime() - 86400000; // one day let processed = 0; let skipped = 0; for (...) { let previousDate = entry.getFieldValue('fld-previousdateidhere'); if (previousDate && previousDate.getTime() > minTime) { skipped++; continue; } entry.setFieldValue('fld-previousdateidhere', new Date()); processed++; if (processed > 100) { break; } // your existing for loop logic here }This uses an extra field and updates when the script is run to set it that way the next time you run the script, it skips past records it’s already “processed” so to speak and moves onto the next batch of 100. Instead of handling the date logic in code, you could also tie this into a saved search as well so that Tap Forms only gives you the candidate records.
December 13, 2020 at 3:12 AM #42839Topic: ipad version issues
in forum Using Tap Forms 5nickc
ParticipantHi Brendan,
Firstly thank you so much for such a useful piece of software. I am using the latest iPad version 5.3.18 and have come across some small issues :- When creating a new field, the description is never shown
- Cannot seem to delete a pick list
- There is an option to colour items in a pick list but this does not work
- Table field entries are not searchable
- fields setup with pick lists using list value not field, still allow you to enter text directly into the field and not pick an entry from the list. Surely a pick list should only allow an entry to be picked from the list of different values. By setting a pick list field to allow multi-select this actually prevents text entry in the field !
These are only minor issues. Otherwise I really enjoy using the software. Keep up the good work,
Thanks
NickDecember 12, 2020 at 7:54 PM #42832Brent S
ParticipantHi Sam and Daniel,
In order to get rid of one of the loops I could move everything to the script. That is, instead of having multiple columns with different data in my CSV file that need to be looked up and replaced,
-
I could reduce the CSV file to a single column that only has the PDF name
. That might solve a number of problems (not only speed, but the ’empty records’)
Then, all the script needs to do is a) find the matching record from the CSV form in the database that has the same PDF name, b) run the rest of the script to populate the fields in that record, and c) repeat for other records in the CSV file until finished.
I know that if I did it this way the end of the script should look something like this if there were two fields to populate.
function Update_Records() {
var csvForm = document.getFormNamed(“csv”);
var contractsForm = document.getFormNamed(“Contracts”);// specifies type of agreement
var type_of_agreement_id = ‘fld-6af499ed439143b297828643341d939b’
record.setFieldValue (type_of_agreement, ‘Licensing Agreement’)// This should “replace” keyword or keywords in a selected record
var agreement_keywords_id = ‘fld-a2126cbe512646e9ba144fb5a90b06dc’;
record.setFieldValue (agreement_keywords_id, ‘Vaccine, Animal, Bacterial’)Could you show me how you would take the original code we had above and simplify the beginning of the script and modify it so it works with the code I have here?
Thanks very much for any insight you can provide.
Cheers,
BrentDecember 9, 2020 at 9:56 PM #42826In reply to: How to search for nothing in a
Sam Moffatt
ParticipantIf you’re after checking if something isn’t “falsy” then you could simplify it to
if (!upper_figure) {and JavaScript will convert it for you automatically. Per that falsy page though, it will treat zero as false.Some of the nuance is that if you haven’t set a value on a field then it is
undefinedbecause it hasn’t been set yet. Tap Forms for many field types maps directly to JavaScript data types. JavaScript will do some amount of type coercion which may result in unexpected results.December 9, 2020 at 12:46 PM #42824In reply to: Adding a Script to Siri
Sam Moffatt
ParticipantOk, so a much simpler test case, just executing this script added via “Add to Siri” in Shortcuts app on its own is enough to reproduce the problem:
function Copy_Pasta() { return "Clipboard contents: " + Utils.copyTextFromClipboard(); } Copy_Pasta();I checked what I was doing and I’m using Shortcuts x-callback-url to trigger the script which explains why it works for me when I do it and not when executed directly through the Shortcuts UI.
I did a quick search and someone mentioned it as a bug for one of the iOS 13 betas but haven’t seen anything else. It could be that Apple is emptying the pasteboard within Shortcuts or at least the context that it hands to Tap Forms as a privacy measure. There might also be a privilege that the intent needs to flag to get the clipboard contents as well but I don’t recall seeing that last I looked.
December 9, 2020 at 10:16 AM #42823In reply to: How to search for nothing in a
Victor Warner
ParticipantDaniel,
Thank you again.
Brendan,
Could you put on the relevant help pages information on searching for nothing for different types of field? It is not easily found and confuse beginners in Javascript. I am used to searching in other apps for nothing with either ” or “” but these do not necessary work with TapForms for some field types.
December 9, 2020 at 1:18 AM #42822In reply to: Adding a Script to Siri
Sebastian
ParticipantHi,
The problem is with copyTextFromClipbard, not with the “To” version.
Please, try calling this script from Shortcuts:
function Copy_Pasta() { // Retrieve the content of the clipboard sent by Shortcuts var info = Utils.copyTextFromClipboard(); // Send back the content of the clipboard to see if it has been correctly retrieved: Utils.copyTextToClipboard(info); return info; }Your testing shortcut may be something like this:
1. Copy something to the clipboard.
2. Call the Tap Forms script “Copy_Pasta”.
3. Retrieve the content of the clipboard (here is where I get ‘undefined’).Thanks for your interest in this matter.
December 8, 2020 at 10:33 PM #42821In reply to: Adding a Script to Siri
Sam Moffatt
ParticipantI recreated what I think you had. I created a form script that looks like this:
function Copy_Pasta() { Utils.copyTextToClipboard("My data - " + new Date()); return hello_world; } Copy_Pasta();Saved it, added it to Siri, enabled Siri, validated that it worked. I then went into Shortcuts, updated the “Run” script that Tap Forms created to disable the “show when run” option, created a new shortcut to run the Shortcut that Tap Forms created and then retrieved the clipboard. Since it copies the date, I can see if it is executing each time. I did also note that the input for my call to the “Run” shortcut listed the clipboard as the input under the “more” option but I’m not sure that matters.
Do you mind using something simple like the above to validate that it’s working and changing over time?
December 8, 2020 at 9:07 AM #42818Topic: How to search for nothing in a
in forum Script TalkVictor Warner
ParticipantI wish to create a script which searches one Number field. If there is nothing there then use another Number field. However, if the first number may have nothing in it (not even a zero), but I cannot work out the search criteria for an empty number field.
For example:
if (upper_figure == ”) {
return total_charge_with_fixed_amount;}
does to produce the desired result if the upper_figure is empty. Nor does
if (upper_figure == null) {
return total_charge_with_fixed_amount;}
What is the correct syntax for an empty Number field?
December 7, 2020 at 9:28 PM #42811In reply to: Some bugs in the latest vs.
Sam Moffatt
ParticipantCase 1: I’ve got a form with 124 fields in it and I personally don’t understand the problem you’re talking about (125 now because I added a test field at the end to see what it did which was focus the field title text box). It doesn’t seem to disrupt me though I might be missing something obvious.
Case 2: Forum is reasonably generous at uploads as well with a max upload size of 4MB, a lot of use cases I manage to fit in that (use smaller window size, don’t record in retina resolutions, squeeze the frame rate down to 15 fps if it isn’t there already). For those that don’t, I put videos on YT as you can upload them as unlisted and get a private link to share.
Sync
Many applications use iCloud to sync in the same way as Tap Forms does, including many Apple apps like Contacts, Notes and more. Agenda is another app I use with iCloud that as changes are made on one device, they become available on all devices. Almost any multiuser based synchronisation system will sync changes as they are made not when you close the document because then you have to wait to upload the data. I would expect any sync solution to be progressive, especially on iOS where you only get time to do work whilst your app is active. iCloud does seem to have issues especially relating to rate limits on non-Apple products which is why I’ve consistently recommended youor own CouchDB for higher throughput.If you want a sync solution where you open the document, you are the only one who makes changes to it and then save it back, you copy your Tap Forms documents to and from more traditional folder sync platforms like Dropbox or iCloud Drive. This would only work on the desktop and there was an earlier thread that described the process. Seems like it worked for them, might work for you. The important thing is that he’s quitting TF and copying the document to and from shared storage each time. If you edit your TF document there directly on two devices, it can corrupt the database as noted in that thread. You could do some scripting to automate this to make it smoother as well.
All told it’s also been noted that Brendan is working to implement another sync backend rather than CouchbaseLite that would add support for Dropbox back though it might be the simple file you are expecting.
reimport: if you’ve got concise use cases you can share where you notice data being transformed inconsistently then I have to assume that would help get any bug that exists fixed, I know in my own coding that when I’ve introduced a bug a concise reproduction case is great for testing and validating the fixes.
Woocommerce: interesting use case, why round trip the data through Tap Forms though? Why not build something in PHP to work with the database or manipulate the data export directly if the ultimate aim is to import back to Woocommerce? Alternatively is there an API for Woocommerce you could use via the Javascript API to more directly interact with the platform?
December 7, 2020 at 3:27 PM #42807In reply to: Extracting contents of a table field
Daniel Leu
ParticipantHi Victor,
I created a new script field underneath the table and use following code:
function Third_Party_Charges_Csv() { // Fetch content from table var third_party_charges = record.getFieldValue('fld-021cfb3cc4f446ddbf5f9463c7b5d620'); // Define field ids from table columns const item_id = 'fld-410bdf5d624a4651b8a803becd9c6578'; const cost_per_item_id = 'fld-6cea4aa73ad44b6f91ba7f566e321790'; const number_id = 'fld-95791fbc24bd4f3ca714756e5dd6a060'; const cost_id = 'fld-a0be1b009c6a4a99a1784d36da134ee3'; var txt = []; // Loop over all entries and fetch field content. for (var n = 0; n < third_party_charges.length; n++){ var third_party_charge = third_party_charges[n]; var item = third_party_charge.getFieldValue(item_id); var cost_per_item = third_party_charge.getFieldValue(cost_per_item_id); var number = third_party_charge.getFieldValue(number_id); var cost = third_party_charge.getFieldValue(cost_id); // Format field content as desired txt.push(n + ". " + item + ": £" + cost_per_item + " x " + number + " = £" + cost); } // Combine each formatted table row return txt.join(" - "); } Third_Party_Charges_Csv();If you want to import this as a CSV into a spreadsheet, you might run into an issue with the ‘-‘ character. It is used as line separater and inside the FCO item.
Hope this helps!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksDecember 7, 2020 at 12:18 PM #42805Topic: Extracting contents of a table field
in forum Script TalkVictor Warner
ParticipantIn a form I have a table field which contains a number of records.
I wish to export the contents of a number of the fields to a CSV (or XLSX) file. But the table field are not exportable.
Is possible to extract the contents of the table field into an another field through a script?
In the attached document the table field (called ‘Third party charges’) contains two records:
Legalisation agent (normal service) £24 1 £24.00
FCO – apostille (normal service) £30 1 £30.00I would like to combine so they become in another field such as (for example):
1. FCO – apostille (normal service): £30 x 1 = £30.00 – 2. Legalisation agent (normal service) = £24 x 1= £24.00
Can a script do this and how would I do it?
Attachments:
You must be logged in to view attached files.December 7, 2020 at 2:09 AM #42803In reply to: Calculations Tutorial
Brendan
KeymasterHi Andy,
There is a video that shows the basic usage of the Formula Editor here:
It’s at 5:45 in the above video.
The description of all the functions available are here:
https://www.tapforms.com/help-mac/5.3/en/topic/calculation
There are four conditional functions. There’s
IF(),IFEMPTY(),IFNOTEMPTY()and theIFEQUAL().They all are based on the concept of logic such that if something happens, then do this, otherwise do that.
For example:
IF(Price < 0; 0; Price)What this means is that if the value of the Price field was less than 0 (negative), then make it 0. Otherwise, just return the Price if it’s 0 or greater than 0.
The other ones work on the same principal.
IFEMPTY(Price; 0; Price)If the Price value is empty, then return a 0, otherwise return whatever the Price value is.
The
IFNOTEMPTY()function is just the opposite:IFNOTEMPTY(Price; Price; 0)The
IFEQUAL()function is only a little different as it takes 4 parameters and is used for comparing strings rather than numeric values like the basicIF()function.IFEQUAL(Field A; Field B; "Equal"; "Not Equal")So in the above, if the value in Field A is equal to the value in Field B, return the text “Equal”, otherwise if they’re not equal, return the text “Not Equal”.
And that’s all there is to it.
Hope that helps!
-
This reply was modified 3 years, 4 months ago by
Brendan.
December 6, 2020 at 9:30 PM #42802In reply to: Some bugs in the latest vs.
martin c
Participantcase one expectations ::
stay put!! not jump to the first field, coz i want maybe?? do other changes to it, then again jump… so do you understand that jumping at 50+ fields can be a problem??
case two::
sure video is great, but not at 4mb atachment limit, where can i send it?? else??
sync::
icloud!!
so, the sync can not happen until you will: by saving, colsing dokument, a situation you are sure you do accept the work…. thats the idea of saving, not saving…. it can not be done on every little change, cos it leads to problems like we have here>> destroying project!! why?? simple solution ::: dokument in the icloud as real file, on storage, accesible via finder, opening closing saving file then the sync… every app does it that way…
reimport::
just wanted to check the conistity of data!! it fails, fields fall apart, records are empty etc…so its the eport or import failure?? is the data exported well?? can i trust??
my case:::
i doing a database work on woocommerce eported csv of products from the shop, 50+ fields , a photo field, where i wanted the filename script to generate filnames in a field, cozz i need it on reimport to woocommerce… its a kind of inventory with photos, kind ob batch modification of fields , all cozz the import of products to worpress woocommerce…
thx
-
AuthorSearch Results