Thank you for the idea Daniel. This application will be used only on an iPad. Unfortunately when I use field scripts they prevent my form scripts from working.
My console.log returns “0” for min and max target.
I will upload my form template as per Brandon. I’m sure I’m missing something simple.
Hi Dan,
If you export your form template (.tff) and post it here, we can look at it and see what’s going wrong with your script.
Thanks,
Brendan
Hmmm… I expected to see a Field Script like this:
var target_id = ‘fld-d984603583864e5fb5af42de33ff177d’;
var last_first_id = ‘fld-b052524e3f814d909bdc1256d5153f51’;
record.getMinOfLinkedFieldForField(target_id, last_first_id);
But for your Form Script, I would check if the values you get are correct:
console.log("min target: " + min_target);
console.log("max target: " + max_target);
I don’t see why you create duplicate a record and then don’t use it.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Many thanks for looking Daniel. You’ll also see some comment out lines I’ve tried.
var date_id = ‘fld-b5cc9a209ab94005862f111287a1c6e8’;
var target_id = ‘fld-d984603583864e5fb5af42de33ff177d’;
var change_id = ‘fld-3f28cc416bf34e9fbe70122e65fb8d22’;
var last_first_id = ‘fld-b052524e3f814d909bdc1256d5153f51’;
//var client_id = ‘fld-cb862ea49ea64d7c8f8fbdbf6cabd80c’;
var min_target = record.getMinOfLinkedFieldForField(target_id, last_first_id);
var max_target = record.getMaxOfLinkedFieldForField(target_id, last_first_id);
//var max_lc_total = record.getMaxOfLinkedFieldForField(target_lc_id, client_id);
var copyOfRecord = record.duplicate();
record.setFieldValue(date_id, new Date());
record.setFieldValue(change_id, (max_target / min_target)-1);
document.saveAllChanges();
Utils.alertWithMessage(‘Script Run Complete!’, ‘Cool!!!!!’);
Do you mind to share your script?
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hello,
I have a parent form called Clients and child form with a number field called Target. I’d like to use record.getMaxOfLinkedFieldForField(linkedFieldID, fieldID); to find the max of Target for each particular client.
I’ve tried using different field ids in the linkedFieldID and fieldID positions and the the script will run without errors but no output is produced.
Are others having success with this?
Kind Regards, Dan
I found the issue. Several field scripts were the cause. I can move them to the record duplicating script.
Hello All,
I have TapForms iPad form connected to a client form via a “linked to form field”. When I run a simple script to duplicate the current record, the duplicate doesn’t show up until I return to list view.
The script:
var copyOfRecord = record.duplicate();
document.saveAllChanges();
This works as hoped in a “Table Field” record, but not otherwise.
I’m surely missing something.
Kind Regards, Dan
I frequently have multiple edit windows open for note or markdown fields, sometimes from the same record and sometimes from multiple records. One problem I keep running into is that I frequently confuse which window is for which notes field because there’s just not enough info in the title to differentiate. As an example, I have three windows open right now on note fields from three rows of a table, and all three are titled Notes - Occurrences – with Notes being the table field’s name and Occurrences being the form’s name, both of which are the same for all three fields/windows. Often when this happens, I end up closing and reopening all of them to straighten things out mentally.
To help, I try to position each window uniquely and then use position as a factor to identifying which window is which. However, this doesn’t get me very far because the main database windows are positionally tied to the edit windows: move the former, and the latter move with it, as though they’re one unit. So if I have multiple databases open at the same time (as I usually do), if I move one of the main windows so that I can better see something else, everything shifts and my spatial system breaks down.
Thus, I’d like to propose adding more information to the title of the edit windows. To ensure there’s always enough info to differentiate, you’d probably need to do something like <form name> - <record’s first sort value> - <field name> [- <row number>], with the last part only applying to table-ish-type fields. That’s probably a bit much, so some configurability would be nice. Ideally, you’d just have a place for me to specify this in the field properties, maybe using tokens or even a calculation/script. Then I could do cool things like mix static text with the DB name, the form name, other field’s values, or a particular table column’s value.
Hi Stephen,
There’s no function in the JavaScript API to change a form’s sort and group settings.
Can you give me a use case for needing this feature?
Thanks,
Brendan
Hi, is it possible to configure sort preferences through a script, as opposed to using “Sort & Group Settings” in the forms inspector panel?
Seems like field.sortOrder simply specifies field order in the form inspector, but maybe I’m misunderstanding its use?
Hi Mike,
There’s a setting on Number fields to display the value red if it’s negative. But not for Date fields that are past due.
But you could use a Script field to return an Emoji character that’s red along with some text perhaps such as “OVERDUE ‼️”
-
This reply was modified 3 years, 6 months ago by
Brendan.
The way Tap Forms separates values for a multi-select Pick List is to separate them by a comma and space character. There’s no function to change that, but what you could do is create a Script field which strips out the comma from the values you set.
The JavaScript function cleanedHashTags = hashTags.replace(",", "") would do what you need.
Unfortunately, there is no API available for that, but I have a game plan!
This is how I would approach this:
1) create JSON object from current record
2) convert JSON object to csv object. A quick google search provides several hits. I like Christian Landgren’s updated solution in https://stackoverflow.com/questions/8847766/how-to-convert-json-to-csv-format-and-store-in-a-variable)
3) copy csv object to clipboard using Utils.copyTextToClipboard(csv_object)
4) call AppleScript using custom URL script to finish up (see https://www.tapforms.com/forums/topic/automator-scripting-auto-folder-creation/#post-47673 for more about that topic). The AppleScript would take the content of the clipboard and save it in a file. It looks like you can upload the file to Google Drive as well.
It should be possible to automate your export steps. But as you can see, there are a few challenges ahead. Good luck and have fun!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Is there a way to automate Tapforms’ existing Export Records function? I’d love to be able to run a script that basically exports the current thing I’m looking at as an Excel file. (Ideally I’d love to have an automated “export, then publish to Google Sheets” kind of functionality, but at the moment I’d be happy just reducing the number of steps.)
I’m an ignoramus of Javascript, though I can hack my way along by modifying others’ code. Same applies to AppleScript.
Thanks in advance for any suggestions!
Mike