Mass Update Knowledge Articles

Dan13
Tera Expert

Our Self Service KB has a default image put into the escalation path that gives end users the different avenues that they can use to contact IT for support. We have an updated image we want to replace it with for any new and current self service articles. I found a script I was able to modify to attempt to automate it, but was unable to get it to work.

 

// Build Query
var knowledge = new GlideRecord('kb_knowledge');

// Execute the query
knowledge.query();

// Print the number of records that will be updated
gs.print(knowledge.getRowCount() + ' records were found.');

// Run a while loop and interate through the records found
while (knowledge.next()) {

 // Update the Escalation Field with the new image
 knowledge.u_kb_escalation_path = '<p><img src="How%20to%20Get%20IT%20Support.png" width="751" height="350"/></p>';
 
  // Updates the record in question
 knowledge.update();
}
 
I'm guessing this might be because the articles are published. Is there a way to get this script to work or would we need to make this change by hand?
1 REPLY 1

Punit S
Giga Guru

It's possible that the script is not working because the articles are published and read-only. In ServiceNow, when an article is published, it becomes read-only and cannot be modified directly.

One solution could be to create a new version of the article, modify the Escalation Field with the new image, and publish the new version. This would allow you to update the image for any new and current self-service articles without modifying the existing published articles.

You can modify your script to create a new version of the article by adding the following lines before updating the record:

// Create a new version of the article
var newVersion = knowledge.createVersion();
newVersion.setValue('u_kb_escalation_path', '<p><img src="How%20to%20Get%20IT%20Support.png" width="751" height="350"/></p>');
newVersion.setWorkflow(false);
newVersion.update();

 

This will create a new version of the article and set the Escalation Field with the new image. The setWorkflow(false) method will prevent the new version from going through the approval workflow. Finally, the update() method will save the new version.

Note that this script will only update articles that have not been modified since deployment. If an article has been modified since deployment, the script will create a new version with the updated image, but the changes made to the article by the end user will not be preserved.

 

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit