Hi Dave,
The Script Editor on the iOS version was built tased upon the Calculation field’s formula editor. If you’re familiar with writing formulas in Tap Forms then hopefully that’ll translate over to using the Script Editor.
When you tap on the script to edit it, a toolbar appears above the keyboard. Tapping on the fx
button is how you access the Snippets, which are the little bits of code that Tap Forms writes for you to do different things. The field
button just to the right of the fx
button is where you access the list of fields. Tapping on a field will insert the appropriate code into the script. You can have Tap Forms generate the record.getFieldValue()
function for you or just generate the var field_name = 'fld-1234....';
code for you.
I’ve also updated the manual to describe a bit about the “magic” that triggers a Script field to execute. Basically any reference to record.getFieldValue(field_id)
in the script will tell Tap Forms to start monitoring the referenced field for changes. If you edit the field value in a record, Tap Forms will look to see if any scripts are referencing that field. If so, it will then execute the script within that Script field.
Form level scripts are executed manually by you. You do that from the action menu button on the records list view by tapping on Run Script and choosing the script to run. You can also edit scripts from there too.
Hope that helps you a bit more.
Thanks!
Brendan
Brendon said:
There’s no manual for the iOS version, but the Mac manual has many of the same concepts.
Well, “concepts” yes, but that’s not sufficient. I’m currently trying to work with scripts on iOS, and the Mac manual refers to objects such as menus which don’t seem to exist as such in the iOS version. For example, I still can’t figure out Form scripts vs script fields in records.
And in any case, the gears and levers of scripts are still opaque to me. For example, the scripts chapter in the Mac manual gives an example of a Movie DB script which runs automatically when barcode information is entered into a record’s field. But from the example given, I can’t see how/why that should happen. There seems to be nothing overt in the script which indicates that action. Apparently there is some invisible TapForms code which “magically does the right thing” in some unspecified set of circumstances. I believe that in one of your Forum posts, you said something to the effect of “when Tap see this in your script, it does <something>”, which is not in the basic description of the operation of “this”. Where is all of this sort of thing documented?
FYI: I’m a retired programmer who completely understands that it’s more fun to write code than to write documentation. But I think that for an app as powerful and useful as Tap Forms, a little more work in the latter might be helpful.
Hi Brendan- Just wanted to ask- I know there has been some discussion about user roles/security/passwords for layouts, etc. I hope you are considering these options in near future updates.
I really love your Tapform program, its easy to design and very user friendly even better than Filemaker Pro I think. I have started designing a small business database CRM/Catalog/Invoice system for my business and it looks like it would work out so beautifully… However, I will need to give access to other sales people on my team to some of the database and wanted to also lock out other parts and especially the “design mode” so that I don’t have layout nightmares with sales people accidentally modifying/deleting set layouts or deleting an entire form or database structures. I need to find a solution if I am to actually use TapForms as my business engine. Do you know if there is any solutions to these matters to use Javascripting or other implementations to making this work with TapForms? I was wondering if these things might be more easily implemented if perhaps there was a way to interface the TapForm core database to perhaps a frontend browser database application such as Open Source NuBuilder Forte https://www.nubuilder.com (which has a user role type setup) or something like it that would work as a internet accessible frontend to TapForms but make it difficult for your staff to screw up hours upon hours of database entry/forms/layouts with one accidental click of the button. Please tell me there is a solution cause up to this point TAPFORM ROCKS! I need a solution ASAP and thought TapForms was it and hope it still can be… Thanks Bro!
Hello Kana,
Thanks for discovering Tap Forms!
The Invoice Tracking template that I have here would be a good start to get you going with building this:
Invoice Tracking Template
It has a Products form that contains a list of products to choose from, plus an Orders form where you create an Order. Within the Order is a Table field called Order Items. The Order Items table has a check button you click on to display a list of Products from the Products form. When you select a Product, its values are copied into the record within the Table field. It uses the names of the sub-fields in the Table field to match up with the names of the fields in the Product form to know what to copy in. From there you can change quantities and prices and whatever you want.
The one thing it doesn’t do is update the quantity in stock of the products after you select the product to add to the Order Items table.
But I think it would be possible to write a Script that could update the quantities on hand in the Products table given the quantities that were entered into the Order Items table for the Order. It would take a bit of work to build a script to do that though. But the basics of what you’re asking for are definitely there in the Invoice Tracking template that you can download.
Thanks!
Brendan
Hi Brendan- The invoice tracking template is a great start. I was just wondering how I could turn it into like a shopping cart/estimate/invoice function to tweak it so that when we go into Order Items that we can have either a button or (autofill feature) to choose from the products table any product to auto populate the form with the correct corresponding product info, i.e., product name, description and price, whether taxable, (and able to order the same product if needed, essentially another line item of the same product with perhaps different quantities entered) which then updates totals- essentially I wanted to turn your invoice template into a shopping cart/Invoice/Estimate functionality. Is Tapforms capable of this? Thanks.
Brendan,
Thank you for the examples (and after a lot of examination at https://www.w3schools.com) I think I have found the JavaScript equivalent:
var number_of_pages_id = 'fld-b6882198382f4b368dccfa874e69a563';
var number_of_pages = record.getFieldValue('fld-b6882198382f4b368dccfa874e69a563');
var extract_from_document_id = 'fld-e3540b375b0f43cb97f4ea84a2705885';
var extract_from_document = record.getFieldValue('fld-e3540b375b0f43cb97f4ea84a2705885');
result = '';
if (number_of_pages == 1 && extract_from_document == 1) {
result = "of an extract (the front of the first page, comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheet of paper)";
} else if (number_of_pages == 1 && extract_from_document == 0) {
result = "(comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheet of paper)";
} else if (number_of_pages > 1 ) {
result = "(comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheets of paper)";
} else {
result = '';
}
result;
Well you can do nested if
statements really easily in JavaScript.
if (numberOfPages == 1) {
if (extractFromDocument == 1) {
// do something
}
}
But this is also the equivalent of:
if (numberOfPages == 1 && extractFromDocument == 1) {
// do something
}
Brendan,
Could you help me if how to do an IF statement within an IF statement in JavaScript based on the code I set out in my original post? I have tried based on the code for the Calculation field but it does not appear to work (most probably because of lack of knowledge of Javascript).
[Number of pages] is a text field.
[Extract from document] is a Check Mark field.
Any help would be very gratefully received (even if it is just the basic outline of how to construct the JavaScript).
It would seem that the (
and )
characters are being interpreted by the Math parser as parentheses for the functions and order of operations even when they’re within double-quotes. I would need to add support to let you escape them like you can a comma, semi-colon, or double-quote.
A workaround for now I would suggest is to use a Script Field instead of a Calculation field to do the same thing. It will also be easier to read in JavaScript than in the formula.
I want to populate a task list form (form A) from a reusable set of activities for things like preparing to travel and setting up camp with my travel trailer and tow vehicle. I created a form (form B) with task fields and created several records representing activities. I created the task list form with a date field and a table (columns names matching the field names in form B). I’ve successfully manually loaded the table in form A with the fields and filtered records from form B. I would like the table in form A to be automatically loaded with a filtered and sorted set of rows from form B when a new record is added to form A. Is this a job for a script? Is there a script example I can use to accomplish this?
Thanks in advance for any help!
Hi Grischa,
You can do queries against the data stored at IBM Cloudant. They have a whole REST API for that. The nice thing about that is you don’t need Tap Forms running to do that.
I do have AppleScript support in Tap Forms which would let you execute a Form Script from an AppleScript. But in testing it I just realized I broke it when I added Siri Shortcuts support on iOS. In order to provide Siri Shortcuts support I had to split my model objects into their own framework and there was a dependency that I commented out which I forgot to add back in which broke AppleScript support. I’ve just fixed it now actually.
One option you might consider is using the Export Tap Forms Archive command if you need JSON output. That generates a .tfarc file which has all the data in it stored in a data.json file within the .tfarc file. That’s just a zip file with a renamed file extension. So you can rename it to .zip and then unzip it and you’ll see the data.json file within it. Now it would be up to you to get the data out of it that you need. Might not be easy though.
Or if you write some JavaScript code to fetch records data, you can then format that as JSON within JavaScript and then use the Utils.postJsonToUrl(json_string, url);
function. There’s not much to it. You just create a JSON string, provide it a URL, then call that function. It will return a dictionary of results. So your web service should return a dictionary for it to use. If you had your own web service you could use this to send it data from Tap Forms. I’m not sure what web application facilities you have available to you though, so I don’t know if this is feasible or not.
Thanks,
Brendan
I’m dealing with a rather sensitive API that times out very often for me. This API returns images and I want to add those images to my forms. To do this I’m iterating over all the records and adding them. But due to the timeouts, sometimes my images don’t get added.
To go around this issue i’d like to count the number of images in a Photo field and if it’s > 0, skip it.
So far I haven’t even been able to access the Photo field. tt.getFieldValue(photo_id_charactersform);
returns undefined.
I have a workaround for this but i’d like to avoid it if possible, as it requires me to manually keep track of how many images a record field has.
Greetings,
this is an advanced question.
I have a complex database with events which I manually export in certain formats to publish them on three different websites.
As I know JavaScript, I would like to somehow retrieve my data as JSON, so I can build web views and display the data according to my needs.
My database is synced with IBM Cloudant.
I saw in the Tap Forms documentation that there is a util called postJsonToUrl but I haven’t found any further documentation.
Do I have to deal with the API of cloudant and complicated SQL requests to retrieve my data or can I use the TapForms API, create a JSON and access it from outside?
Thanks in advance,
Grischa
I think I have solved the problem:
I added near the top of the script:
result = '':
and the error message disappeared and the script runs properly (and the now the request for help with the if statement become superfluous (at least in my limited testing).
I think I have solved the problem:
I added near the top of the script:
result = '':
`
and the error message disappeared and the script runs properly.