- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 08:08 AM
Hello,
URGENT
I require a fix script to bulk update category field of the published knowledge article. Yes, I'm aware of (glide.knowman.versioning.enable_minor_edits) this system property but our organization is not allowing us to enable it so i require a fix script as alternative.
I gathered this fix script but it not working as expected :
Could anyone please help.
var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("workflow_state=published^short_description=test"); // Change the encoded query to target published articles with a specific short description if needed
kb.query();
while (kb.next()) {
kb.category = "Suppliers"; // Set the category field to "Email"
kb.update();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 12:28 PM
Hi @SM123 ,
I tried your problem in my PDI and it works for me please make some changes in your script like there is no field called categeroy instead of kb_category and you have to pass the sys_id of emial category as I did in below scirpt. This is working in my PDI.
var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("workflow_state=published^short_description=test"); // Change the encoded query to target published articles with a specific short description if needed
kb.query();
while (kb.next()) {
gs.print("Herhe")
kb.kb_category = "5681bf8bff0221009b20ffffffffff95"; // Set the category field to "Email" Set sysid of email here
kb.update();
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 08:48 AM
I just ran this in my PDI and was able to make updates, what isn't working for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 10:11 AM
@SM123 - it looks like you are setting 'category' instead of 'kb_category'. Also the category value should be set to a sys_id rather than a name value. You may be running into a business rule that blocks edits to a published article which can be fixed by using setworkflow(false) in you script. I have provided an example below:
var new_category_name = "Suppliers";
var category_id = new GlideRecord('kb_category');
if(category_id.get('label', new_category_name)){
var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("workflow_state=published^short_description=test"); // Change the encoded query to target published articles with a specific short description if needed
kb.query();
while (kb.next()) {
kb.setValue('kb_category', category_id);
kb.setWorkflow(false); // Prevent workflow and Business rules from running on update
kb.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 12:28 PM
Hi @SM123 ,
I tried your problem in my PDI and it works for me please make some changes in your script like there is no field called categeroy instead of kb_category and you have to pass the sys_id of emial category as I did in below scirpt. This is working in my PDI.
var kb = new GlideRecord("kb_knowledge");
kb.addEncodedQuery("workflow_state=published^short_description=test"); // Change the encoded query to target published articles with a specific short description if needed
kb.query();
while (kb.next()) {
gs.print("Herhe")
kb.kb_category = "5681bf8bff0221009b20ffffffffff95"; // Set the category field to "Email" Set sysid of email here
kb.update();
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak