From e76300871819f9ab606029e9d35ebb8f038d61a7 Mon Sep 17 00:00:00 2001 From: Chris Newman Date: Thu, 15 Dec 2022 10:57:47 -0500 Subject: [PATCH] Create at_delete_orphaned_subscriptions.js --- at_delete_orphaned_subscriptions.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 at_delete_orphaned_subscriptions.js diff --git a/at_delete_orphaned_subscriptions.js b/at_delete_orphaned_subscriptions.js new file mode 100644 index 0000000..8bdeb19 --- /dev/null +++ b/at_delete_orphaned_subscriptions.js @@ -0,0 +1,11 @@ +// Delete all subscriptions no longer attached to a +// subscriber, or where the value is zero +let subscriptionsTable = base.getTable('Subscriptions'); +let subscriptionsView = subscriptionsTable.getView('Grid view'); + +let subscriptionsResults = await subscriptionsView.selectRecordsAsync({fields: ['Subscribers','Monthly Rate','Number of Shares']}); +for(let shareRecord of subscriptionsResults.records){ + if(shareRecord.getCellValueAsString('Subscribers').length == 0 || shareRecord.getCellValue('Number of Shares') == 0){ + await subscriptionsTable.deleteRecordAsync(shareRecord.id); + } +}