Update a field in a dataset when a date field equal Today

Hi,

I have a dataset A with a field “date” and a field “status”

I want to be able to update the status to the value “pending” when the field “date” equals to Today.

This action is not before any insertion, update, delete, etc…
Thus, I guess I can’t use Hook ?

Any advise about this request ?

Thanks for your help
Regards,
pym

Hi Pym,

Currently there is no option to add scheduled tasks to wix code.
Therefore you will have to use hooks to first check if date = today, and if so, modify its status to pending and return the new item.

Depending on your specific usage, you will probably need to use beforeUpdate, beforeGet and/or beforeQuery.

Hi Ido,

Thanks for your help.
I implemented based on your idea with a hook on beforeQuery… The problem is I feel important slowness to consult pages…

And moreover, it seems not working everytime ?
Thanks again
regards,
pym

var TodaysDate = new Date(); 
var TodaysDate2 = new Date(); 

TodaysDate.setDate(TodaysDate.getDate() - 1); 
console.log(TodaysDate); 
console.log(TodaysDate2); 

let itemResults; 

wixData.query("flightDataset") 
	.between("flightDate", TodaysDate, TodaysDate2) 
	.find() 
	.then((results) => { 
		itemResults = results.items[0]; 
		console.log(itemResults); 
		**itemResults.flightStatus = "Pending";** 
		**wixData.save("flightDataset", itemResults);** 
		console.log(itemResults); 
	}) 
	.catch((err) => { 
		let errorMsg = err; 
		console.log(errorMsg); 
	});

I build a site for a company that has subscription periods. For example, there is a customer who takes a subscription for a month, three months, a year. I would like to define that pressing three months will add three months alone.
I actually asked how do I add months using the code of course, for example in the selection on the three months will return the start date + 3 months?
Thank you

Hi,
Can you please send your question in a new thread?

Thanks,
Tal.