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?
Hi @preethi.ramiah,
Welcome to the forums!
I think you have two main options here:
- Instead of a
cutOffDatefield, use Scheduled Unpublishing to automatically unpublish certainquestionrecords 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 bycutOffDate >= 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?