I had a need to get the script field ID which isn’t readily available in the Script Editor and decided to do a quick form script so that I could pick it up later. If you’ve used my ‘Script Manager’ form convention, then just create a new form script in it called ‘Form Logger’.
You can call it without arguments to get all fields dumped, here’s some sample calling code:
document.getFormNamed('Script Manager').runScriptNamed('Form Logger');
formLogger.dump()
If you want to filter by type, you can specify the field type:
document.getFormNamed('Script Manager').runScriptNamed('Form Logger');
formLogger.dump({'type': ['script', 'text']});
And this is it’s output in the console:
Form Logger: Shipments
Type Filter: ["script","text"]
Layout: default
fld-c487390743c947969cbe661cff596855: text Tracking Number
fld-0950c430cb0c41f79c51d43a544b366b: text Carrier
fld-7a29242731d9451092c92d8586dbc94a: script Tracking Details
fld-dddcdc15e1c44aa4a99bba6314dc7a07: script Tracking URL Autocomplete
fld-9bee4fd0919e4b439e7bed8d5a6c1053: script Tracking Number Reformat
fld-2cd0296ea0884c8cba3640d8e33f010b: script Checkbox Flip Flop
fld-a9a09a61a9e949199e92d47c02fd364c: text Shipment Order ID
fld-f7aba3b5ddd6430cb8e9a211e0086c84: script Date Propagation
fld-45c8f29ec3214fc5aacbba73e2de3142: script Order ID FK
*Note:* This won’t look as formatted in the console because it uses a proportional font.
Here’s the full script, it’s pretty simple:
// ========== Form Logger Start ========== //
// NAME: Form Logger
// VERSION: 1.0.1
// CHANGELOG:
// 1.0.1: Added support for custom form name and fix for "getId" rename.
/**
* Method to dump out the field ID's, type and names with the ability to filter by type.
*/
if (formLogger == undefined)
var formLogger = (function() {
return {
dump: function({type = [], layout = 'default', formName = ''} = {})
{
let targetForm = form;
if (formName)
{
targetForm = document.getFormNamed(formName);
}
console.log('Form Logger: ' + targetForm.name);
console.log('Type Filter: ' + JSON.stringify(type));
console.log('Layout: ' + layout);
var fields = targetForm.getFields();
for (field in fields)
{
if (type.length == 0 || type.includes(fields[field].fieldType))
{
console.log(fields[field].getId() + ": " + fields[field].fieldType + "\t" + fields[field].name);
}
}
}
}
})();
// ========== Form Logger End ========== //
As you might gather, I want to have a layout additional filter but haven’t gotten there yet. Maybe in a later version.
form.selectRecord() just selects the record. It doesn’t specifically do it for the Default Layout. It displays whatever the last layout that was selected. Tap Forms stores that information in a preferences file (DocumentProperties.plist) within the .tapforms document so it knows what layout to display the next time you view a form’s records.
It definitely sounds interesting and useful to add some more UI automation features to the scripting engine.
Hi Brendan,
I work on a CRM system using Tapfroms where I would like to guide the user (eg, me:) along the way. I used custom layouts to add a new client, quotations, orders, and sales. Each has its own form and custom layout.
On the client form, I would like to have buttons for ‘quotation’, ‘order’, ‘invoice’. etc. Clicking a button would trigger a script that creates a new record in the respective form. Next I would like to display directly the custom layout to enter the needed information, eg, form.showLayoutNamed(‘my fancy quotation layout’);.
I haven’t seen anything in the documentation supporting this. Is this something that could be added? This would make it much easier to implement flow-like applications and guide the user along.
Thanks,
Daniel
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thanks for your answers.
iCloud for the device and for Tap Forms works but you cant restore from previous version with these solutions.
In fact, you can with device iCloud backup, but it’s totally incontrollable as we dont know exactly the date, and there is only 1-2 restore point.
T think of a create a iOS reminder but i dont know how to do that with the script function.
Thank you.
I haven’t written any scripting code to allow you to write a script that lets you automate a backup on iOS. On macOS quitting the app can trigger an automatic backup, but not on the iOS version. You have to tap the + button on the Backup & Restore screen periodically to create a backup file manually.
Thanks Sam / Brendan – I created a script and brought the date(s) to the parent form. I can now search using the General Search.
thanks,
rocky
Hi, is there a way to create a backup automatically, for example when leave app, or sometime when working on the bdd?
Only on iOS please, a script can handle the job to click on the + on the Backup & Restore window ?!
Thank you for yours ideas!
Starting with modelling the data is probably the first problem and then move on from there. Like any database, you’re only going to get so far before you need to teach it some of your custom logic and processes.
That said I write a lot of scripting for Tap Forms to help automate a lot of data entry and speed up common tasks. Scripting added a massive power boost for Tap Forms capability wise to enable all sorts of interesting functionality.
The script I posted for combining multiple values from a child form should also work for tables. I use this to make parent fields searchable by values in their child fields.
Hi Rocky,
That’s right. Date fields can’t be searched via the general search. You need a Saved Search for that. However, Date fields within a Table field can’t be searched at all. I only index the text and numeric data types within a Table field. You could do it by adding a Script field to your parent form which extracts out the date values from your Table field into a single Script field in the parent form. That way when you do a general search you’ll be searching the parent form, not the Table field’s records directly.
Thanks,
Brendan
If you’re looking to do a simple field, something like this should work as the contents of a script field. The first few lines set up some variables and get the current values. One thing to note that I use a variable to store the photo field ID because we’re going to use that again later. There is a basic sanity check that if the photo field is empty and the URL is set then go add to the field. If you don’t have this then it’ll keep trying to add to the field (photo fields support multiple images). This should let you delete the image and then if you change the URL again, it’ll download a new image to the field.
var photo_field_id = 'fld-1234';
var photo_field = record.getFieldValue(photo_field_id);
var url_field = record.getFieldValue('fld-4321');
if (photo_field.length == 0 && url_field.length > 0)
{
record.addPhotoFromUrlToField(url_field, photo_field);
}
I’ve just written this here on the forum, I haven’t tested it so there might be a bug. You’ll have to replace the field ID’s with your own fields but it should work.
Have you tried it just using the record.addPhotoFromUrlToField(url, fieldID) function and a hard-coded URL? Where fieldID will be the ID of the Photo field.
To get the URL value from another field, just double-click on the Website address field in the Script Editor and Tap Forms will generate code to get the value.
e.g.
var url_field = record.getFieldValue('some-field-id');
Don’t forget to call form.saveAllChanges(); after.
Thanks,
Brendan
Hi all,
I’m trying to fetch a web image into a TapForms image field with “record.addPhotoFromUrlToField(url, fieldID);”, but I couldn’t find an example anywhere. Is there some script around for a start?
At the end I would like to use a TapForms URL field to enter the path, and get the image which is on the web-server loaded into the image field.
Thx a lot for your help
Tom
Ok maybe that whole process/program thing was a bridge too far. All I really need is for the information to be organized and trackable in the way I described. I suspect learning the in-and-outs of tapforms will be project enough without having to delve into javascript. Whatever I can do to automate at least the accounting side I am hoping can be done in tapforms without any scripting but the main things would seem to be having things organized well by drive type, then model, then inventory (serials) and then assign serials to sales and remove from inventory (maybe just by transferring that record to the sales sheet/form). A lot of the math could be done with basic spreadsheet type functions but putting that together with serial number tracking and in a nice-to-work-with form(at) is what I am hoping tapforms can do. Not to mention barcode scanning/printing.
Thanks,
s
Does tapforms have this sort of “process” ability? where I can start a process like “receiving” for entering new inventory and “sale” for entering sales record info and removing inventory?
Maybe.
For your use case with the hard drives, my guess is this is a basic process that might work:
– you order a bunch of drives from an upstream manufacturer (could be it’s own form)
– you receive those drives and they all have individual serials, you can load these into a drive form
– you make a sale to a customer and create an invoice and link various drives to them
First one you could put in Tap Forms or not, it does capture the start but also superfluous. The second one seems like your entry point for Tap Forms, you create new drive records when you receive and catalog them. Then the next step is an invoice table linked to your drive. Now Tap Forms will let you link all of this together with two or three forms no worries, what it won’t inherently enforce are your business rules.
You could set up an invoice form with a link to the drive form so that you can select candidate drives. This will work but runs the risk that Tap Forms will display everything in that form, including ones you’ve already sold. A potential solution is in fact two drive forms, one with “available” drives and another with “sold” drives where you move records from one form to the other. That’s possible to do but would interact awkwardly with the Tap Forms UI because the same data will be split across two forms.
If you’re fine eschewing the UI a little and happy to spend some quality time with Javascript, then you can use form scripts to automate some of the process. You could set up a saved search for “unsold” drives (e.g. ones not linked to a sale/invoice) and then implement a pre-check to make sure that the drive you just scanned isn’t already sold before linking it to a new invoice. Of course if you link it to an invoice that gets returned or similar then you’d have to unlink the drive from the invoice.
Whilst Tap Forms has a barcode scanner feature built in on iOS, a Bluetooth barcode scanner for your desktop will likely help you speed through this as well. It could also help you on the phone but I’d personally suggest automating via the desktop this functionality. If you can find a programmable Bluetooth barcode scanner that will let you append “Command+N” to the end then you could do really quick data input.
Without some work, Tap Forms can do some of what you want in terms of the data model but that wouldn’t enable the full process management. With some script fields and form scripts, you could automate most of the process to work for what you need with the checks you want. I’m not going to say yes because it’s going to require some scripting work to fully realise but it’s definitely not no: a solid maybe.