My code (below) has no red squiggles but doesn’t populate the text box. Can you help me figure it out?
What I want to happen:
In a dynamic page, I would like to present text in a text box (#text314) by looking up two datasets.
The two datasets:
The first dataset has rows of clients with fields of client information. The second dataset has rows of services we offer clients.
The first dataset is #dynamicDataset (named UNPLUG.Circadian). The second is #dataset1 (named MICRO-CHANGES).
The fields:
I have a reference field in the main #dynamicDataset that looks at the second #dataset1 and, in this instance, I’ve selected the row title ‘Get Daylight’ from the dropdown.
And in the ‘Get Daylight’ row in the second dataset (#dataset1) I have a field called ‘instruction’ which contains the text I want to display in #text314.
import wixData from 'wix-data';
$w.onReady(function () {
// Get the current item from the UNPLUG.Circadian dataset
const currentItem = $w('#dynamicDataset').getCurrentItem();
// Get the value of the em1Practice field
const selectedServiceTitle = currentItem.em1Practice;
// Use the value of em1Practice to search for the corresponding service in #dataset1
wixData.query('MICRO-CHANGES')
.eq('title', selectedServiceTitle)
.find()
.then(results => {
// Get the instruction from the first result returned
const instruction = results.items[0].instruction;
// Set the text of #text314 to the instruction
$w('#text314').text = instruction;
})
.catch(err => {
console.error(err);
});
});