Create a fix script to remove the extra string from the Short description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 07:33 AM
I need to remove the string starting with "IT Support:" from all the knowledge articles short descriptions. i.e if the short description is "IT Support: How to enable user account" then it should rename to "How to enable user account". Need to update the short descriptions of all the knowledge articles starting with "IT Support:"
Can someone help me how to write the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 12:58 PM
Hi, something like this should work
//string that you want to find/replace
var myString = 'IT Support:';
//first query the table
var checkRecord = new GlideRecord('yourTargetTable');
//addQuery or encodedQuery if required.
checkRecord.query();
while(checkRecord.next()) {
//now test each records short description for existance of your string using indexOf
if(checkRecord.short_description.indexOf(myString) > -1) {
//replace the string with any empty string and trim any white space.
checkRecord.short_description = checkRecord.short_description.replace(myString, '').trim();
//Now update the record without triggering anything
checkRecord.setWorkflow(false);
checkRecord.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 05:42 AM
Hi Tony,
Thank you for the response, in addition i also have the sys_id's of the articles appended to the short description, how can i remove that too from the name?
eg: "IT Support:da1b51ab1b63cc90c001a8a4bd4bcb39 "How to enable user account"
where "da1b51ab1b63cc90c001a8a4bd4bcb39" is the sys_id of the article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 10:11 AM
Hi Tony,
I am using the below script to update the records, since my string also contain the sys_id of the record after "IT Support: 763822295dgdbssjww63fcnyysr678 <Short_Description>
var myString = 'IT Support';
var checkRecord = new GlideRecord('kb_knowledge');
checkRecord.addEncodedQuery('number', "KB0643829");
checkRecord.query();
while(checkRecord.next()) {
if(checkRecord.short_description.indexOf(myString) > -1) {
checkRecord.short_description = checkRecord.short_description.replace(myString, '').trim();
var regexp = /[0-9a-f]{32}/;
var out = (checkRecord.short_description.match(regexp));
checkRecord.short_description = checkRecord.short_description.replace(out, '').trim();
checkRecord.setWorkflow(false);
checkRecord.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 05:53 PM
Try as below
var str = "IT Support";
var gr = new GlideRecord('kb_article');
gr.addEncodedQuery("short_descriptionSTARTSWITHIT Support")
gr.query();
while(gr.next()) {
if(gr.short_description.startsWith(str)) {
gr.short_description = gr.short_description.replace(myString,'').trim();
gr.setWorkflow(false);
gr.update();
}
}
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.