Background script to replace words in article body in Knowledge base

Andrew_TND
Mega Sage
Mega Sage

Hello,

This is probably really simple but wouldn't know how to script it.

To give you some background we have knowledge base articles which mention specific assignment groups but every now and again these assignment groups are renamed and as you can imagine could cause some confusion.

What I want to do if its possible is to run a background script on the knowledge base which searches the 'text' field, finds and replaces the old value with the new value.

1 ACCEPTED SOLUTION

Jan Cernocky
Tera Guru

Hi Andrew,

you may try something like this (e.g. replace 'aaa' by 'bbb')

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('text','CONTAINS','aaa');
gr.query();
while(gr.next()) {    
    oldText = gr.getValue('text');
    newText = oldText.replaceAll('aaa','bbb');
    gr.text = newText;
    gr.update();
}

It seems it is not breaking the approval process in my PDI but be cautions about your actual process. The KB may change the state from 'Published' which I believe is not wanted.

View solution in original post

1 REPLY 1

Jan Cernocky
Tera Guru

Hi Andrew,

you may try something like this (e.g. replace 'aaa' by 'bbb')

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('text','CONTAINS','aaa');
gr.query();
while(gr.next()) {    
    oldText = gr.getValue('text');
    newText = oldText.replaceAll('aaa','bbb');
    gr.text = newText;
    gr.update();
}

It seems it is not breaking the approval process in my PDI but be cautions about your actual process. The KB may change the state from 'Published' which I believe is not wanted.