I forgot to say I have separate Scripts for the iOS version and the Mac version of Tap Forms given some iOS limitations. The one above is the iOS version and below is the Mac version.
var myForm = document.getFormNamed('Travel Database');
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var results_comments = [];
var selected;
function copy_comments( comments ) {
Utils.copyTextToClipboard( comments );
}
function copy_result_multiple( comments ) {
if ( comments == true ) {
console.log( 'Index:' + results.indexOf( selected ) );
console.log( results_comments[ results.indexOf( selected ) ] );
copy_comments( results_comments[ results.indexOf( selected ) ] );
} else {
console.log( 'Cancelled' );
}
}
function multiple_results( all_results ) {
let prompter = Prompter.new();
prompter.cancelButtonTitle = 'cancel';
prompter.continueButtonTitle = 'Copy Comment';
prompter.addParameter('Select Result ', 'selected', 'popup', all_results)
.show('Multiple Results Found', copy_result_multiple );
}
function search_records( haystack , needle ) {
var location_id = 'fld-cf720b6ab4314f0bb5f47bc9bd61f0a9';
var comment_id = 'fld-0096b55f012d4d4fb34a95f784951b55';
var rec;
for (rec of haystack) {
if ( rec.getFieldValue( location_id ).includes( needle ) ) {
results.push( rec.getFieldValue( location_id ) );
results_comments.push( rec.getFieldValue( comment_id ) );
result_count++;
}
}
if( result_count == 0 ){
console.log( 'No results found!' );
}else if( result_count > 1 ){
//multiple results
multiple_results( results );
}else{
//single result
copy_comments( results[0] );
}
}
search_records( records , search_term );
I have a Script that used to work perfectly but has stopped working in recent versions of Tap Forms and can’t workout why.
The script is supposed to take a search term from clipboard, do a search, if one result is found bring up a screen displaying the “Comments” field and also copy it to the clipboard. If multiple results are found it presents them, you pick one and then it also displays the “Comments” field of the selected one and copies it to the clipboard. What has stopped this working? I’m not getting any errors in the Console and the variable references are correct.
var myForm = document.getFormNamed('Travel Database');
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var selected;
function copy_comments( comments ) {
Utils.copyTextToClipboard( comments );
}
function multiple_results() {
var joined = '--multiple_matches--';
var res;
for (res of results) {
joined = joined +
res.location + '::' + res.comment;
}
copy_comments( joined );
}
function search_records( haystack , needle ) {
var location_id = 'fld-c55265c3f56b43feb423f5a198dffe6c';
var comment_id = 'fld-141d923e785148e3aec84576c746a4a4';
var rec;
for (const rec of haystack) {
if ( rec.getFieldValue( location_id ).toLowerCase().includes( needle.toLowerCase() ) ) {
results.push( { location: rec.getFieldValue( location_id ) , comment: rec.getFieldValue( comment_id ) } );
result_count++;
}
}
if( result_count == 0 ){
console.log( 'No results found!' );
}else if( result_count > 1 ){
multiple_results();
}else{
copy_comments( results[0].comment );
}
}
search_records( records , search_term );
Hi Daniel Doh no picture !, I’ve re-attached but if it doesn’t attach the error is “ ReferenceError: Can’t find variable: record, line:(null)”
But actually when I select the record and then test the script (prompted by your reply) it does seem to work , so maybe a non issue (user error)
Thanks
Matt
Assign following single line to a script field:
record.getId();
You might need to click on the recalculate formulas icon to get the field updated. To avoid this, you can add a dummy getFieldValue at the beginning of the script:
var name = record.getFieldValue('fld-xxxx');
record.getId();
The name variable is not used, but this way, the script is triggered when something changes with the name field. Obviously, use a field that exists in your form.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
I did a video on building a script that joins a couple of values together and also shows an example of using the child records loop. Shows how to use the editor to put stuff together and also how to use extra values with the child records loop. Hopefully it’s helpful or useful.
Hi Michael,
If both your fields are in the same form, then all you need to do is, in the Script Editor, double-click on the field you want to copy from. Tap Forms will write the code for you to retrieve the current value of that field.
Then, look at the Snippets and double-click on the Set Field Value snippet. That’ll insert the command into your code at the cursor position that will set a value for a field.
Here’s an example of copying a value from one field to another:
function CopyScript() {
var from_field_id = 'fld-.....';
var from_field_value = record.getFieldValue(from_field_id);
var to_field_id = 'fld-.....';
record.setFieldValue(to_field_id, from_field_value);
}
CopyScript();
So when the from_field is changed, whatever value was in it will be copied to the to_field.
What you want to do with the from field value however is up to you. This is just a straight copy. But you may want to check the value, compare it with something, then set a different value into the to_field.
Not sure if this has already been posted or seen , but it’s not showing in my list of posts so I will re post my questions.
I am interested in understanding how scripts work and I read the dummies script lesson and still have no idea how it works. I have looked for videos on Youtube and found one that was still a bit complicated for me. I have read the definition sheets , JavaScript API sheet, that gives a brief explanation, however I am still scratching my head…. yes a really dummy.
I have been through the script forum and I was wondering if someone could write me a simple script so I can copy and learn from there.
Maybe theres a simple script video available… I am very much a monkey see monkey do kinda guy.
I would like to populate a field entered on a form ,not linked, and have that field auto populate another on same form.
Thank you for your time.
Kind regards
Michael
Thank you for your certainly very valuable suggestions. Unfortunately, scripting is beyond my capabilities :-(
Hi Michael,
1. You could do this with a Script field. You would have to write a script that looks at Field A, and then sets some value onto Field B after Field A has had its value set.
2. Yes. There’s a Default Value option on many field types that you can specify. When you create a new record, the Default Value will be copied into the field.
3. On macOS there’s a custom layout feature where you can place fields anywhere you want. But on iOS, the label is on the left and the value is on the right.
4. The Mac version has an Access Controls function on a per form basis. So you can password protect a form and you can prevent people without the password from modifying it, adding, deleting, or updating records. The iOS version has a limited version of this feature where you can password protect a form and the form structure cannot be changed. But not all the other access controls.
Thanks,
Brendan
Calculation fields will only let you do aggregate operations on fields that have multiple values (table fields, link to/form form on a many relationship). For numeric values there are more options but non-numeric fields generally results in a simple count.
Scripting will give you access to each record and let you do what ever operation you need. One of the other forum members has done a Tap Forms JavaScript Scripting 101 and the Scripting 102 has a section on looping through records. You can use Javascript template strings to relatively easily build strings with text field values.
Thank you for the clarification. I successfully copied the values (all text values) from one form into the other form via a table field, as suggested. However, in the next step, using such values together with values in other fields of the receiving form in a Calculation field seems not to work (the calculation always seems to end up into a COUNT()-function), but is crucial to my use of Tap Forms. And no, I have no knowledge of scripting, but hope/expect that this should work out of Tap Forms as is (at least I didn’t find anywhere any restriction in this direction to the contrary). Did I miss something?
Thank you for an incredibly swift response. Impressive!
To 1. above: This unfortunately doesn’t really reply to my question. is there a regular Boolean search possible (NOT, AND, OR, Parentheses ( ), Quotes ” ”)? The popup button on the Saved Search edit popover view only explains to AND and OR. Can I enter some advanced boolean query into the ‘Search term’ entry box? If yes, what would be the syntax for such advanced queries? What about truncated search (all instances that end on ‘….searchstring’? What about wildcards? Is there somewhere a comprehensive description of all search possibilities on the Mac (I have understood that the search functionalities on iOS are limited to some extent).
To 2. above: Ok, solves this issue. I am mostly interested in features on the Mac.
To 3. above: Understood. I am nevertheless unhappy with the way this works.
You would need to use a Script to copy the data into fields of the parent form. When you have relationships between forms, it’s basically just a reference to the records stored in the other form. So if you delete the record in the other form, you’re deleting the reference too. The same goes if you make changes.
However, if you were to use a Table field and link the Table field to another form, when you select records from that other form, the values are copied into the Table field. So even if you delete the original record or make changes to it, it won’t affect the display of the records in the Table field. A Table field also has the added advantage that you can add additional sub-fields to it. This could be useful for example, if you had a Product form and an Order Items Table field. You could select items from the Product form that gets copied into the Order Items Table field and you could have an additional Quantity field which you can then specify what the quantity is.
Look for my Invoice Tracking sample document in the Template Exchange forum to see an example of this in action.
Thanks,
Brendan
I am new to Tap Forms and I have no knowledge of Java Script (I am basically coming from early FileMaker).
1. Is there a more comprehensive explanation available of search capabilities in Version 5.3 than the little explanation provided in the online ‘Manual’, which is just not enough. E.g is there finally regular Boolean search possible (NOT, AND, OR, Parentheses ( ), Quotes ” ”)?
2. How do I search in Version 5.3 e.g. records in which Value A may appear in field 1 OR value B may appear in field 2, but in no case Value C appears in field C.
3. Is there a way to avoid that after every advanced search, the search is saved and populates the side bar to the left?