When a record is deleted from an App, I want a way to back up the data.
Some approaches that I thought of:
Setting up a Webhook that runs on deletion, but I found out the Webhook data does not contain record data.
So now I am planning to back up the data using JavaScript customization instead. I was thinking of using app.record.detail.delete.submit.success, which runs on deletion, but it seems that the record data is not included in the event object.
Finally, I am thinking of using the app.record.detail.delete.submit.success event, then calling the Get Record API with kintone.api() to get the record data. Then I will use that data to back it up in a different place (maybe inside another App, or sending it to an iPaaS).
This seems like quite a long approach to the solution, so I want to check whether this sounds correct before proceeding with the customization.
const events = [
'app.record.detail.delete.submit',
'app.record.index.delete.submit'
];
kintone.events.on(events, function(event) {
const record = event.record;
// Back up the record here
return event;
});
These Delete Events also support Promises, so if your backup process is asynchronous, you can wait for it to complete before allowing the deletion to proceed. This also gives you the option of preventing the deletion if the backup fails.
On the other hand, app.record.detail.delete.submit.success runs after the record has already been successfully deleted. Therefore, calling the Get Record API from that event would be too late to retrieve the deleted record. The corresponding success event for deletion from the record list page is app.record.index.delete.submit.success.
One thing to keep in mind is that this approach is based on Kintone's JavaScript deletion events, so if records can also be deleted through other methods, such as the REST API, those deletion paths would need to be considered separately. Kintone provides a separate Delete Records REST API for API-based deletion.