Join the Webstudio community

Updated 4 weeks ago

Collection Data filtering with a Javascript

Hello everyone,
I am currently struggling with a customer requirement. The situation is as follows. We use a Notion CMS which lists events.
Now the customer wants to be able to specify in a field when the event will be displayed on the website.

Field name for the date entry: ‘Live event’
Field name for sorting: ‘Event date’

Now I can't solve this statically because of the date synchronisation, but need a dynamic solution that always synchronises the current date with the ‘Live event’ field.

The CoPilot code gives me the following suggestion:


const moment = require('moment-timezone');
const berlinTime = moment().tz('Europe/Berlin').format(); // Dynamische Berliner Zeit

const response = await notion.databases.query({
database_id: 'YOUR_DATABASE_ID',
filter: {
property: "Liveschaltung",
date: {
on_or_after: berlinTime // Dynamische Berliner Zeit
}
},
sorts: [
{
property: "Veranstaltungsdatum",
direction: "ascending"
}
]
});


Now I cannot use the Javascript in the body of the collection. Any suggestions on how I could implement this?
I also have the question of how I can best store the Notion API data. I'm not quite sure how to do that either.

Looking forward to your help, thank you ❤️
p
1 comment
resolved :

Found a way to make a Notion Formular to calculated this and give out a Checkbox with yes or no.
Add a reply
Sign up and join the conversation on Discord