Hi everyone,
I have a date field in a database, and I want to change an other field when the date is equal to today’s date.
I used an hook Before Query to trigger the event on every refresh of the database, so when the date will be on today, I’ll update a field for example a boolean “EventIsPassed”
The problem is, I can’t manage to get all the items of my base in the hook event, to select the value I need next…
I didn’t find someone who had the same problem I have.
If someone knows what could help me, it would be really appreciated.
Thank you in advance.
I think I managed to find where the problem is :
It looks like the ‘After Query’ hook don’t support the async method…
I actually used once for a ‘Before Insert’ hook and it’s working.
So that would means async is not supported on all hooks?
That’s really strange…
Hi Brut,
Actually we do support async method on hooks as described in https://www.wix.com/code/reference/wix-data.Hooks.html
afterQuery handles item by item, so you are free to update all of the items that way
in your case it should be something like
export async function new_afterQuery(item, context) {
return Object.assign({}, item, {hasPassed: item.date < new Date()})
}
In case you dont want to handle item by item but rather query for the item for additional data you can also do the following
export async function new_afterQuery(item, context) {
const additionalData = await wixData.get(‘Collection’, ‘itemId’)
return Object.assign({}, item, {additional: additionalData.additional})
}
Thanks
Adi