Skip to main content

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

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }

ServiceNow - script include: build up the results as a JSON object (array) - example 2

function call var sCurrentGroupMembers = new <script_include> (). getGroupMembers ( group_sysid ); gs . print ( 'sCurrentGroupMembers:' + sCurrentGroupMembers ); var oGroupMembers = JSON . parse ( sCurrentGroupMembers ); gs . print ( JSON . stringify ( oGroupMembers . users )); oNewGroupMember = JSON . parse ( group_members ); var oGroupConfig = getGroupDeltas ( oGroupMembers . users , oNewGroupMember ); gs . print ( JSON . stringify ( oGroupConfig . remove )); gs . print ( JSON . stringify ( oGroupConfig . add )) output : *** Script: sCurrentGroupMembers: {"manager":"3b2649efdb0f8c10cc0652f3f39xxxxx", "email":"", "type":"33a2226edb99c340edfc7cbdae96xxxx", "description":"Created for xyz", "users":[{"user":"3b2649efdb0f8c10cc0652f3f396xxxx"},{"user":"856a8f71db3d73041b4ffc45ae96196a"},{"user":"3752771