I am a relative newbie with JavaScript. I am using the database app Tap Forms. I want a script to take a search term off the clipboard, do a search and get the record ID for the found item and then copy that to the clipboard. It isn’t working so could someone tell me what I have done wrong?
The JavaScript API for the app is at https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
My code is:
The JavaScript API for the app is at https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
My code is:
JavaScript:
var myForm = document.getFormNamed('Scope RE');
var records = myForm.getRecords();
var search_term = Utils.copyTextFromClipboard();
var result_count = 0;
var results = [];
var selected;
function search_records( haystack , needle ) {
var name_id = 'fld-90984efc3585456ab56763adff0a5228';
var rec;
for (const rec of haystack) {
if ( rec.getFieldValue( name_id ).toLowerCase().includes( needle.toLowerCase() ) ) {
results.push( { name: rec.getFieldValue( name )
} );
result_count++;
}
}
if( result_count == 0 ){
console.log( 'No results found!' );
}else if( result_count > 1 ){
multiple_results();
}else{
copy_record.getId( results[0] );
}
}