Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Script Talk › Script to conduct a search
- This topic has 3 replies, 3 voices, and was last updated 2 years ago by
Daniel Leu.
-
AuthorPosts
-
October 18, 2023 at 1:10 AM #49995
David GoldParticipantI don’t know JavaScript so I was wondering if someone could help me with a simple script for the iOS app that does a search of a database for a term called “input” of a database called Boral with a form called Boral Data and searched a field called Name (I can add the field ID where it is needed)?
Any assistance would be much appreciated.
October 18, 2023 at 6:41 PM #49998
David GoldParticipantI’ve had a go at it cutting and pasting from some other scripts but can’t work out why it’s not working. Am getting an error in the console saying:
var myForm = document.getFormNamed(‘Boral’);
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var selected;function copy_name( name ) {
Utils.copyTextToClipboard( name );
}function multiple_results() {
var joined = ‘–multiple_matches–‘;
var res;
for (res of results) {
joined = joined +
res.name;
}
copy_comments( joined );
}function search_records( haystack , needle ) {
var name_id = ‘fld-1acb38c0b51b44698849501507b51722’;
var rec;for (const rec of haystack) {
if ( rec.getFieldValue( name ).toLowerCase().includes( needle.toLowerCase() ) ) {
results.push( { location: rec.getFieldValue( name_id ) } );
result_count++;
}}
if( result_count == 0 ){
console.log( ‘No results found!’ );
}else if( result_count > 1 ){
multiple_results();
}else{
copy_name( results[0].name );
}}
search_records( records , search_term );
-
This reply was modified 2 years ago by
David Gold.
October 20, 2023 at 6:16 PM #50015
BrendanKeymasterWhat is the error message?
October 20, 2023 at 8:10 PM #50024
Daniel LeuParticipant@brendan, it moved over on this thread https://www.tapforms.com/forums/topic/open-record-as-result/#post-50023
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks -
This reply was modified 2 years ago by
-
AuthorPosts
You must be logged in to reply to this topic.