I 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.
I’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 1 year, 2 months ago by David Gold.
What is the error message?