Error executing query

Hello,
I am running a query but I get an error TypeError: Cannot read property ‘Name’ of undefined

The query is below… Am I missing something or just being stupid :slight_smile: Polite answers only to that question :slight_smile:

export function button1_click(event, $w) {
//Add your code for this event here:
console.log(“Running Test…”); //Just added this for debug purposes

wixData.query("tkkMembers") 
  .eq("SquadNumber", 6) 
  .find() 
  .then( (results) => { 
    let items = results.items; 
	let item = items[0]; 
	let Name = item.Name; 
	console.log(Name); 
  } ) 
  .catch( (err) => { 
    let errorMsg = err; 
    console.log(errorMsg); 
  } ); 

}

You do not have a field key starting with an uppercase letter. Have you tried the below?

let Name = item.name;

Hi Andreas. I have tried your suggestion, still get the same error. :frowning:

I would guess your query isn’t returning any results. Can you put in a console.log() to see what results.items is and/or results.items.length.

Check your Field Key for the Name field:
let Name = item.Name ;
I suspect that the Field Key is name :
let Name = item.name ;

Umm, sorry, I see that Andreas previously suggested check the Field Key. I was lazy in my previous post and should have also suggested checking the field SquadNumber :
Check the Field Key :
.eq(“squadNumber”, 6)
Also, is SquadNumber a number field, or is it text?

In other words, check all Field Keys , and check field types to make sure the query is valid.

Guys,

thank you for your advice. I was using the the Field Name SquadNumber rather than the field key: squadNumber. It is now working :slight_smile:
Again, my sincere thanks.