I have cut the code down to the core problem I am struggling with. Any help very much appreciated as I tried lots of things now and it feels like it should an easy solution. Though it’s all a learning curve to me. I found the solution now and updated it here. Return on the async function was missing.
Import {fetchRecordItem} from ‘public/BackOffice.js’
import {SearchDatatbase } from ‘public/BackOffice.js’
//searchKey passes the value of event.key pressed in the input box (not shown)//
.then((results) => {
if (results.totalCount >0) { //Check records found if so then display//
$w('#firstNameText').text = results.items[0].firstName;
$w('#lasttNameText').text = results.items[0].lastName;
}
}
});
//**********************Public BackOffice.js file ********************************//
export function searchDatatbase (dataBaseName, searchKey) {
Screen elements cannot be accessed from Public files using the $w context selector since a Public file does not have a page context. The following code that you posted will not work:
//Public BackOffice.js//
export function SearchDatatbase (dataBaseName,keypress){
let searchKey= $w('#InputFirstName').value; // invalid use of $w
Instead, you can pass the searchKey to the SearchDatatbase() function.
Thank you for the assistance I left the onReady in by mistake when trying things. I have amended the code taking on board your advice ’ Screen elements cannot be accessed from Public files using the $w context selector’ However the problem of returning the results to the page code function still remains. I am probably doing something stupid again but still struggle resolve the issue. Thank you for your time and help I do appreciate it. Coz
@jonatandor35 Thanks for the fast reply and guidance. I have amended the .query() thank you. My validateKey functions takes care of presenting query
upper and lower case issue, I left it out to make it clearer. However my original problem still persist of returning results back to my page code function ? No doubt something else daft I am doing. ?
$w(‘#text1’).text =results.items[0].firstName; //Works fine to here //
return (results) //does not return results to page code?