want to change knowledge article author via fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â06-14-2023 03:56 AM
Hi,
I want to change knowledge article author via fix script. can you please help me with script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â06-14-2023 04:51 AM
Hi @nitin51 ,
If you want to change the author of all Knowledge Articles without considering the old author name
Table: kb_knowledge
// Define the new author name
var newAuthorName = 'New Author';
// Create a new GlideRecord instance for kb_knowledge table
var knowledgeGR = new GlideRecord('kb_knowledge');
// Query all knowledge articles
knowledgeGR.query();
// Loop through the records and update the author to the new value
while (knowledgeGR.next()) {
knowledgeGR.author = newAuthorName;
knowledgeGR.update();
}
// Print the number of articles updated
gs.info("Number of articles updated: " + knowledgeGR.getRowCount());
If you want to change the author for only specific records instead of all records, you can add conditions to the GlideRecord query to narrow down the set of Knowledge Articles that will be updated
// Define the new author name
var newAuthorName = 'New Author';
// Create a new GlideRecord instance for kb_knowledge table
var knowledgeGR = new GlideRecord('kb_knowledge');
// Add conditions to filter the articles you want to update
knowledgeGR.addQuery('sys_id', 'IN', ['article1_sys_id', 'article2_sys_id', 'article3_sys_id']);
// Add more conditions as needed, such as category, state, etc.
knowledgeGR.query();
// Loop through the records and update the author to the new value
while (knowledgeGR.next()) {
knowledgeGR.author = newAuthorName;
knowledgeGR.update();
}
// Print the number of articles updated
gs.info("Number of articles updated: " + knowledgeGR.getRowCount());
Based on the old and new author names
//Define the old and new author names
var oldAuthorName = 'Old Author';
var newAuthorName = 'New Author';
// Create a new GlideRecord instance for kb_knowledge table
var knowledgeGR = new GlideRecord('kb_knowledge');
// Add a condition to filter the articles by the old author
knowledgeGR.addQuery('author', oldAuthorName);
knowledgeGR.query();
// Loop through the records and update the author to the new value
while (knowledgeGR.next()) {
knowledgeGR.author = newAuthorName;
knowledgeGR.update();
}
// Print the number of articles updated
gs.info("Number of articles updated: " + knowledgeGR.getRowCount());
Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-17-2023 02:07 AM
Hi @nitin51 ,
please mark the post as correct solution as well, it helps others who are having similar issue
Shravan
Please mark this as helpful and correct answer, if this helps you