Unlink a record in background

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:

  1. Instead of a cutOffDate field, use Scheduled Unpublishing to automatically unpublish certain question records 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)
  2. If you must use the cutOffDate field, 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:

  1. List records and use the filter object to filter by cutOffDate >= today. Make sure you account for any potential time zone differences!
  2. Save their record IDs in an array.
  3. 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?