We have a
question set model with a field named
questions that is linked to
multiple question model. Each question record has a
cutOffDate field after which we want the record to be unlinked from the question set record. This should happen in the background without user intervention. How can we achieve this?
We have a
Welcome to the forums!
I think you have two main options here:
- Instead of a
cutOffDatefield, use Scheduled Unpublishing to automatically unpublish certain
questionrecords after a date. This would be the easiest because it doesn’t involve any developer time (i.e., no code needed – it’s a built-in feature of the DatoCMS admin dashboard)
- If you must use the
cutOffDatefield, I’m afraid you would have to write an external script to handle this via the DatoCMS Content Management API.
Example logic for such a script, if needed:
- List records and use the
filterobject to filter by
cutOffDate >= today. Make sure you account for any potential time zone differences!
- Save their record IDs in an array.
- Bulk destroy those records by ID (be very careful and make sure you have your filters right!!). If you don’t need to destroy them outright, bulk unpublish might be safer.
If you don’t have infrastructure set up to host a script on a cron job, something like a Cloudflare Worker on a cron trigger should be able to do the job.
Does that help?