In my workflows, I have started to archive records from one table in a different table, based on specific criteria.
I do this via API using Python, as such:
data = grist_WN.fetch_table('WebReg')
for record_to_archive in data:
# Copy to WebReg_Archive
if record_to_archive.discard == True or record_to_archive.reg == True or record_to_archive.over == True:
grist_WN.add_records('WebReg_Archive', [
{ 'tweet': record_to_archive.tweet,
'id': record_to_archive.id,
'url': record_to_archive.url,
'website': record_to_archive.website,
'provider': record_to_archive.provider,
'discard': record_to_archive.discard,
'title': record_to_archive.title,
'date': record_to_archive.date,
'reg': record_to_archive.reg,
'notes': record_to_archive.notes,
'contact': record_to_archive.contact,
'updated_by': record_to_archive.updated_by,
'updated_og': record_to_archive.updated,
'tz': record_to_archive.tz,
'provider_og': record_to_archive.provider_og,
'over': record_to_archive.over,
}
])
# Delete from WebReg
grist_WN.delete_records('WebReg', [
record_to_archive.id,
])
It works, but quite verbose, especially as I need to write this for quite a few tables.
What would be great is the ability to pass via API the original Grist objects (namedtuple?), instead of having to deconstruct each field, so the above could be written and done just with this:
list_WN001_archive = [record for record in grist_WN.fetch_table('WebReg') if record.discard == True or record.reg == True or record.over == True]
grist_WN.add_records('WebReg_Archive', list_WN001_archive)
grist_WN.delete_records('WebReg', list_WN001_archive)