On January 1, 2020 a lot of people will wake up with a headache. While some will be due to the previous night's activities, others will be due to a disappearing Knowledge Base, and a lack of systematic delegation.

What is KB-pocalypse?

ServiceNow's default date value has always been set to 2020-01-01. While this was a good 'future' date to use, the future is now here! This means that some records won't be viewed as valid once the new year begins.

Some examples are:

  • Delegates: Delegate records have a default 'ends' date of 2020-01-01. All delegations with this end date will no longer be active.
  • Knowledge Base: If your knowledge articles have a Valid to (valid_to) date of 2020-01-01, then they won't be visible to anybody searching for them through the Service Portal, or searching/browsing the Knowledge homepage.

How can I see if this impacts me?

Running the script below will show you what tables still have this default value, and how many records still have a date of 2020-01-01.

/*
This script will find all dictionary entries that are using 2020-01-01 as a default date, and tell you the number of impacted records. 

To actually make changes, you will want to change the update flag to true;

*/

//change this flag to true if you want to update the dictionary entries and affected records
var update = false; 

//Update this value as yyyy-mm-dd
var newDefaultDate = "2030-01-01"; 

var gd = new GlideDate(); 
gd.setValue(newDefaultDate); 
gd.getDisplayValue();

var gdt = new GlideDate(); 
gdt.setValue(newDefaultDate+' 23:59:59'); 
gdt.getDisplayValue();


if(!update){
    gs.print("Since the update flag is false, we are not making upates to these records.");
}

var dictionaryEntry = new GlideRecord("sys_dictionary");
dictionaryEntry.addEncodedQuery("default_valueLIKE2020-01-01^active=true^internal_type=glide_date^ORinternal_type=glide_date_time");
dictionaryEntry.query();
while(dictionaryEntry.next()){
    var table = new GlideRecord(dictionaryEntry.name.toString());
    table.addEncodedQuery(dictionaryEntry.element.toString()+"ON2020-01-01@javascript:gs.dateGenerate('2020-01-01','start')@javascript:gs.dateGenerate('2020-01-01','end')");
    table.query();
    if(table.hasNext()){
        gs.print("There are "+table.getRowCount()+ " "+dictionaryEntry.name.toString()+" records with a "+dictionaryEntry.element.toString()+" date of 2020-01-01");
        if(update){
            var newDate  = dictionaryEntry.internal_type == "glide_date" ? gd.getDisplayValue() : gdt.getDisplayValue();
            while(table.next()){
                table.setValue(dictionaryEntry.element.toString(), newDate);
                table.update();
            }
        }
    } else{
        gs.print("The "+dictionaryEntry.name.toString()+" table still has this default value, but doesn't have any records.");
    }

    if(update){
        dictionaryEntry.default_value = dictionaryEntry.default_value.replace(/2020-01-01/gi, newDefaultDate);
        dictionaryEntry.update();
    }
}

Also available on GitHub.

How can I fix it?

You can fix this by completing the following:

  1. Change all the affected records as identified above
  2. Updating the dictionary entry so that future records won't still default to 2020-01-01.

Please note that the above script will do this for you if you change the update flag to true.

WRITTEN BY:

Toby Comer

Senior Technical Architect