/**
 * Background script to delete all records older than 7 days from the import set tables.
 */
var stagingTableNames = [
        'x_turbo_turbonomic_ws_action_approval',
        'x_turbo_turbonomic_ws_action_record',
        'x_turbo_turbonomic_ws_change_request',
        'x_turbo_turbonomic_ws_entity',
        'x_turbo_turbonomic_ws_instance'
    ];

// Go back in time 7 days
var daysAgo = new GlideDateTime();
daysAgo.addDaysUTC(-7);

var query = 'sys_created_on<' + daysAgo.getValue();

for (var i = 0; i < stagingTableNames.length; i++) {
    var gr = new GlideRecord(stagingTableNames[i]);
    gr.setWorkflow(false);
    gr.autoSysFields(false);
    gr.addQuery(query);

    // Delete all records older than 7 days from the import set table
    gr.deleteMultiple();
}
