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

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue' href=hr_profile.do?sysparm_query=number=" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

GlideRecord setValue

setValue(String name, Object value) Sets the specified field to the specified value. Normally a script would do a direct assignment, for example,  gr.category = value . However, if in a script the element name is a variable, then  gr.setValue(elementName, value)  can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter. This method cannot be used on journal fields. If the value parameter is null, the record is not updated, and an error is not thrown https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object