Hi guys,
Can someone please help me out here. I’m trying to setup a scheduled job to check a database, and change the Expiry date, based on todays date. I’ve created a jsw job that is trying to check a database for any entries that have expired, and then change the status to ‘Expired’.
import wixData from ‘wix-data’ ;
export function expireLicense() {
let today = new Date();
const options = {
day: “numeric” ,
month: “medium” ,
year: “numeric”
};
wixData.query( “Students” )
.lt( “expiryDate” , today)
.find()
.then((results) => {
if (results.items.length > 0 ) {
let items = results.items;
//loop through all the items and update the relevant ones
items.foreach(item => {
//item.eventPast = true;
wixData.bulkUpdate( "Students" , "status" , 'Expired' )
})
}
})
. catch ((err) => {
let errorMsg = err;
});
}
I’ve then got a job.config that calls the jsw job at a certain time every day.
{
“jobs” : [
{
“functionLocation” : “/LicenseExpire/ExpireLicense.jsw” ,
“functionName” : “expireLicense” ,
“description” : “This expires all licenses that have passed todays date” ,
“executionConfig” : {
“time” : “18:14”
}
}
]
}
Any suggestions, would be greatly appreciated.