Skip to main content

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

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:

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

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.addQuery('name', 'custom-Azure Billing Query Based On Role');
if ( {
    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


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

    var Tgr = new GlideRecord(tableName);
    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
        gs.log(tableName + ':: table truncate END', 'fixScr_16482');

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


(ServiceNow )


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'" + 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!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object