Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript TapForms and Javascript

dgold

New Coder
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:
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] );
    }

}
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom