Duplicate knowledge article numbers

Kasia5
Tera Contributor

Hi All

 

Because of import data and incorrect transform map the knowledge article numbers have been duplicated so as example:

I have two totally different articles but they have the same Number.

As a proposed solution I received this one:
https://www.servicenow.com/community/servicenow-ai-platform-articles/re-numbering-duplicate-kb-artic...

 

But I see some comments that it is not always working as expected, any idea how to change the Number like KB0012345 in knowledge articles (in this ones which have been loaded with incorrect transform map)?

 

Thanks in advance for help

1 REPLY 1

Its_Azar
Kilo Sage

Hi there @Kasia5 

 

If you want to renumber them here is the Background script

 

var dup = new GlideAggregate('kb_knowledge');
dup.addAggregate('COUNT', 'number');
dup.groupBy('number');
dup.addHaving('COUNT', '>', 1);
dup.query();

while (dup.next()) {

    var kbNumber = dup.getValue('number');
    var count = parseInt(dup.getAggregate('COUNT', 'number'), 10);

    gs.info('Fixing duplicate KB number: ' + kbNumber + ' (' + count + ' records)');

    var gr = new GlideRecord('kb_knowledge');
    gr.addQuery('number', kbNumber);
    gr.orderBy('sys_created_on'); // keep oldest as-is
    gr.query();

    var first = true;
    while (gr.next()) {


        if (first) {
            first = false;
            continue;
        }

        gr.setValue('number', '');
        gr.update(); 
    }
}

 

This is renumber the KB articles. for explame if you have KB12345 twice, it keeps one with same name and changes the other kb article to diff num. 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.