We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Replace string within knowledge article on all places

Rushi2
Tera Expert
Hi All, 
 
I am trying to replace one string in the knowledge article using the below script, it's not working.
 
Can anyone help me here 
 
var count = 0;
var ArticleGR = new GlideRecord('kb_knowledge');

ArticleGR.setLimit(100);
ArticleGR.setWorkflow(false);
ArticleGR.autoSysFields(false);
ArticleGR.query();
while (ArticleGR.next()) {
    var CanReadList = ArticleGR.u_kb_support_details;
    CanReadList = CanReadList.replace(/Assignment Group/g, 'Assignment');
    ArticleGR.u_kb_support_details = CanReadList;
    ArticleGR.update();

}
gs.log("KB replace count" + count);
 
Thanks,
Rushi
5 REPLIES 5

Harish Bainsla
Kilo Patron

var count = 0;
var ArticleGR = new GlideRecord('kb_knowledge');

ArticleGR.setLimit(100);
ArticleGR.setWorkflow(false);
ArticleGR.autoSysFields(false);
ArticleGR.query();

while (ArticleGR.next()) {
var CanReadList = ArticleGR.u_kb_support_details;

// Use the global replace() function to replace all occurrences
var updatedCanReadList = CanReadList.replace(/Assignment Group/g, 'Assignment');

if (updatedCanReadList !== CanReadList) {
ArticleGR.u_kb_support_details = updatedCanReadList;
ArticleGR.update();
count++;
}
}

gs.log("KB replace count: " + count);