Skip to content

Commit

Permalink
Create at_delete_orphaned_subscriptions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cnative100 authored Dec 15, 2022
1 parent 15afb21 commit e763008
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions at_delete_orphaned_subscriptions.js
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit e763008

Please sign in to comment.