Avoid data loss when reference column is deleted

Hi everyone,

I have the following structure:

  • 1 table for exam dates
  • 1 table with a grading list for all exams

In my data, I reference the respective exam date in my grading list. However, if I want to delete an old exam date (there is no need to keep those), it removes the exam date in my grading list.

Question: is there a way to to delete the reference without loosing the information that was referenced? I have looked at the Function reference, but there doesn’t seem to be a suitable option. I had though of something similar to the PEEK function, which notices a deletion and extracts the information at this point.

Regards

You can do this with a small workaround. In your grading table, you’ll need to add another column, of type Text, that serves as a backup in case the reference is lost. Provide this column with a trigger formula that triggers whenever the reference column changes. Then for the formula, do something like this:

import json
if not $Name_of_your_ref_column:
   return value   # If the ref column is empty (or the ref that was there previously got lost), don't alter this column at all.
try:
   return json.dumps(RECORD($Name_of_your_ref_column))  # Make a copy of the record currently referenced by the ref column and turn it into a string representation in JSON format, so it can be stored in this text column.
except:
   raise ValueError("Couldn't parse the referenced record as JSON for some reason.")

This way, you’ll end up with a backup of your reference data that’s stored in a fixed, never-going-anywhere, text column. Of course you’d have to write some additional code to work with this JSON data and extract from it whatever info you may need to keep around. Use json.loads(...your_json_data...) as a starting point.

Hope this helps!