Return Certain Field of Database

Hello, so I have a “Participants” database where someone can pass in their name and then depending on if a boolean from the database is true or false, I want to display a video. I think I have most of the code down, I just cannot figure out how to show the results of a query for a particular field rather than the entire item. Sorry if this was not specific enough, let me know if I need to clarify anything. Thank you!

Hi Terrence,

Welcome to WixCode.

Maybe this code example will help:

	wixData.query("Participants")
	  .eq("lastName", "Smith")
	  .find()
	  .then( (results) => {
	    let items = results.items;
		let item = items[0];
		let firstName = item.firstName;
		console.log(firstName);
	  } )
	  .catch( (err) => {
	    let errorMsg = err;
	    console.log(errorMsg);
	  } );

The query looks in the Participants collection for a participant with the last name Smith, We get the first (and we hope only) item from the array of results.items, get the first name of the participant from the firstName field, and then display the participant’s first name in the Developers console.

I hope this is what you were looking for.

Yisrael

1 Like

Hi Yisrael, that was exactly what I was looking for! Thank you so much. Could you also help me with my other post? It has been awhile and no one else has answered yet. I have attached the link. Thanks

Hey Yisrael ,

Thanks for your solved answer. It worked only one time.
When I tried it with another field then it’s throwing error.

Do I need to use any “.onReady()” function as it’s not working If I want same result button click?

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

Hi Wix Team,
I am also having trouble with getting this to work for me. I am trying to set up a dynamic quote based on user input. So want to run a look up on my connected dataset based on user input selections. Where column A of dataset would be the permutation of the user input (i.e. Quote Type), and column B the Quote Price. I want to return the Quote price and then display it (also wish to save this value in the form that gets submitted back to another dataset).

Code isn’t working well, I can get the concatenated “Quote Type” based on user selections - this is named ‘tagConcat’ in the code. But only get returned undefined currently. Have been looking at the documentation but not making any progress so assistance would be very helpful! Thanks in advance.

Site Page: https://editor.wix.com/html/editor/web/renderer/edit/2ad2e6ba-cd16-468a-a2f2-e20436e17e91?metaSiteId=30633f59-c0e1-4412-bbf5-4519620dd743&editorSessionId=946c99a7-0ecb-4d3d-9ab0-64b9545cbdf2&referralInfo=my-account

Code:
import wixData from ‘wix-data’
$w.onReady( function () {
});
export function dropdown1_change(event) {
let size = $w(“#dropdown1”).value
console.log(size);
}
export function checkboxGroup1_change(event) {
let reporttype = $w(“#checkboxGroup1”).value
console.log(reporttype);
let tagConcat = ${$w('#dropdown1').value} ${$w('#checkboxGroup1').value};
console.log(tagConcat);
wixData.query(“QuotePricing”)
.eq(“title”, “tagConcat”)
.find()
.then( (results) => {
let items = results.items;
let item = items[0];
let quotePrice = item.quotePrice;
console.log(quotePrice);
$w(“#text12”).value = “quotePrice”;

}
)
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
}

Hi there,

You are posting on more than a year old thread. Please create a new post with you issue as it will make it more visible.