See the code snippets used in the video at the bottom of this post.
Watch how to automate your workflow with Corvid by Wix. In this video, we’ll show you have to use the Job Scheduler tool to execute timed tasks on a daily, weekly or monthly basis.
import wixData from 'wix-data';
export function clearOldListings() {
// Querying all the items in the collection.
return wixData.query("apartmentListings").find().then(results => {
// Declaring a variable for an expiration date to test by initiating it as a date object.
let expirationDate = new Date();
// Setting the expiration date for 3 months prior.
expirationDate.setMonth(expirationDate.getMonth() - 3);
// Using the forEach method to create a filtered array with listings older than 3 months.
let oldListings = results.items.filter(item => item.uploadedOn < expirationDate);
oldListings.forEach(item => {
// Removing each of this items from the collection.
wixData.remove("apartmentListings", item._id);
})
})
}
Hoping you can help. Here is what i need it to do (very similar to the above). I need the job to run every night at 11.59pm and remove any events that have the ‘finishedDate’ for that days date (todays date).
Or even update the status to remove it from the listings (change boolean to false).
Hi Robert,
Sorry for the late reply, I haven’t quite understood what you are trying to accomplish
can you maybe explain further and/or share your site URL or just your code?
@liorwi Hey, thank you for getting back to me. Really appreciate that.
I am looking to basically update the Boolean ‘Status’ on my ‘Events’ database once an event date is past (by looking at the Finished Date and the Time field, and if it’s past, then update the ‘Status’ of the Boolean to True on the Database.
We should maybe run the scheduled job every day at 1 minute past midnight, UK time - to remove any finished dates for yesterday?
Does this make more sense? Could really be doing with some help to make this work as i really don’t understand Scheduled Jobs.
@contact53319
Hi Robert, With pleasure!
I think I understand but it would help me look at the code itself, do you mind sharing your site address so I can take a look?