One of my user input element (box) is connected to 'dataset1'. After filtering 'dataset1' by 'date', I obtain a 'text' result. What is the code to insert this 'text' into a 'dataset2' with the specific 'fieldname' and 'fieldkey' in the row that already contains the same 'date'?
Thanks a lot for your assistance
Hi Ido,
Thanks again for your kind reply. I sort of understand this 'promise' issue but am still lost though ...
I have adjusted a bit your code as I think the 'placeofevent' was not defined properly before
QUOTE
$w('#novemberdataset').getItems().then( (result) => {
let place = result.items.title;
wixData.query('#registrationdataset').eq("dateOfEvent", place)
.then( result => {
});
});
UNQUOTE
And I still cannot figure out how to add this 'place' value into my 'registrations' DB while calling the appropriate _id.
I appreciate your assistance very much. Thanks
Hi,
let placeofevent = $w('#novemberdataset').getItems().then(result => result.items.filter(row => row.title));
This line should not produce any result since the call getItems() is async.
The easiest way to make this work is by chaining multiple promises together:
$w('#novemberdataset').getItems().then(result => {
let place = placeofevent(result.items[0].title);
wixData.query('#registrationdataset').eq("dateOfEvent", place).then( result =>{
//Do something with results
}
)
}
);
You can find more information on promises here and here
Hi Ido,
Thank you very much for your reply. I have attempted to follow your solution but I face difficulties ... Here is the exact situation:
QUOTE
import wixData from "wix-data";
export function dateofevent_change() {
//Filtering the Schedule DB with selected Date of Event. Only the details of this specific event are isolated //(THIS PART WORKS FINE)
$w("#novemberdataset").onReady( () => {
const date = $w('#dateofevent').value;
$w('#novemberdataset').setFilter(wixData.filter().eq('monthlyRank',date));
//Depending on Date of Event choosen, determine Place of Event. (AMONG DETAILS OF EVENT, I WANT //TO ISOLATE THE PLACE OF EVENT (IT IS IN THE 'title' KEY IN THE SCHEDULE DB) (THIS PART DOES //NOT WORK ...)
let placeofevent = $w('#novemberdataset').getItems().then(result => result.items.filter(row => row.title));
//And then add Place of Event into the Registrations DB (IN REGISTRATION DB, CORRESPONDING FIELD //KEY IS 'dateOfEvent' ... SORRY FOR THE MESS!!). NOT SURE BELOW LINE IS CORRECT ...
$w('#registrationdataset').onReady ( () => {
wixData.query('#registrationdataset').eq("dateOfEvent", placeofevent);
//HERE I CANNOT FIGURE OUT HOW TO USE THE _id OF THE MATCHING INTEM FIELD IN //'registrationdataset' AND CALL AN update() TO ADD THE VALUE INTO THE DB ('dateOfEvent' FIELD //KEY)
});
});
}
UNQUOTE
Thanking you very much for your assistance,
Hi,
To get the selected item, call getCurrentItem, once you have the required value, you will need to call query() 'dataset2' and match it with the obtained 'text'.
To complete the process, use the _id of the matching field in 'dataset2' and call update() to modify it.