ServiceNow truncating very large tables which are no longer used - and example

Issue:
Request regarding the deletion of records on the following tables
- azure_billing_daily
- azure_billing_monthly

Business Impact:
Tables have not been used since 2018

Solution Proposed:
This is a common question regarding data management. We have an article which provides several methods to handle the data and possible deletions:

https://support.servicenow.com/kb?id=kb_article_view&sys_kb_id=fbc46dd2db266010c9c302d5ca9619a5



The article covers the following four topics:
UI actions
Clone exclude rules
Table cleanup policies
JavaScript

We recommend testing in subproduction environment(s) prior to any implementation in production. ServiceNow does not intervene in data removal requests unless the presence of those records are causing a business critical operation to be unusable.

Next Steps:
Would you be able to review the cleanup methods mentioned and let us know if you have any additional questions. We would be happy to follow up.

 

 =================

example script - tables no longer used:

var grBusRule = new GlideRecord('sys_script');
grBusRule.addActiveQuery();
grBusRule.addQuery('name', 'custom-Azure Billing Query Based On Role');
grBusRule.query();
if (grBusRule.next()) {
    gs.log('PLEASE DISABLE BUSINESS RULE "custom-Azure Billing Query Based On Roles" BEFORE PROCEEDING', 'fixScr_16482');
    
} else {

    var stable1 = "azure_billing_daily"; //--4M +records
    var stable2 = "cloud_mgmt_billing_daily"; //--2.5M +records
    var stable3 = "cloud_mgmt_tag_history_map"; //--874K +records
    var stable4 = "cloud_mgmt_rsrc_tag_history"; //--226K+ records
    var stable5 = "azure_billing_monthly"; //--156K +records


    truncateAzureTable(stable1); //--timing: took approx 40 mins for the largest table
    /*truncateAzureTable(stable2);
    truncateAzureTable(stable3);
    truncateAzureTable(stable4);
    truncateAzureTable(stable5);*/

}

function truncateAzureTable(tableName) {
    var bTruncate = false;
    bTruncate = true;

    var Tgr = new GlideRecord(tableName);
    Tgr.query();
    if (bTruncate) {
        gs.log(tableName + ':: table truncate START', 'fixScr_16482');
        /*skip business rules*/
        Tgr.autoSysFields(false); //--leave last updated intact
        Tgr.setWorkflow(false); //--skip business rules and notifications
        Tgr.deleteMultiple();
        gs.log(tableName + ':: table truncate END', 'fixScr_16482');

    } else {
        gs.print(tableName + '--TABLE ROW COUNT: ' + Tgr.getRowCount());

    }
}

(ServiceNow )

Comments

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage