- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 01:32 AM
Hello Community,
We have a business use case where we wish to create new knowledge bases and categories in our instance and then update the knowledge base and category for our existing articles.
We have found a script here Migrating knowledge articles between Knowledge Bases via a script - Support and Troubleshooting (ser... which works in principle but there is a caveat at the foot of this article which says you need to do it for all versions. This is where we have the block, does anyone know how we can adapt and leverage this script so that it will make the updates to all versions of the article?
All help appreciated as ever.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2024 05:22 AM
With this script, you can just switch the if to a while, as the KB number across versions remains the same, but new sys_ids are created.
var TARGET_KB_SYS_ID = '988e3392db5410508c46adc3ca961939';
var TARGET_KB_CATEGORY = '0bc35fc91b7d1950540c1138b04bcbbf';
var KB_ARTICLES_TO_MOVE = [
"KB0011889", //sample KB numbers
"KB0011888"
];
for (var i = 0; i < KB_ARTICLES_TO_MOVE.length; i++) {
moveKBArticle(KB_ARTICLES_TO_MOVE[i]);
}
function moveKBArticle(kbNumber) {
var kb = new GlideRecord('kb_knowledge');
kb.autoSysFields(false);
kb.setWorkflow(false);
kb.addQuery('number', kbNumber);
kb.query();
if(!kb.hasNext()){
gs.info('Did not find ' + kbNumber);
return;
}
while (kb.next()) {
kb.kb_knowledge_base = TARGET_KB_SYS_ID;
kb.kb_category = TARGET_KB_CATEGORY;
kb.update();
gs.info('Moved ' + kbNumber + ' to Knowledge Base ' + TARGET_KB_SYS_ID);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 05:24 AM
I have made some small changes to the script and it appears to work when the corresponding sys_ids are listed instead
var TARGET_KB_SYS_ID = '988e3392db5410508c46adc3ca961939';
var TARGET_KB_CATEGORY = '0bc35fc91b7d1950540c1138b04bcbbf';
var KB_ARTICLES_TO_MOVE = [
"08f7e3a547000e10ddab97f8736d434c", //sample KB sys_id
"e23e90f71b4a0a50790efee5d34bcb02"
];
for (var i = 0; i < KB_ARTICLES_TO_MOVE.length; i++) {
moveKBArticle(KB_ARTICLES_TO_MOVE[i]);
}
function moveKBArticle(kbSysid) {
var kb = new GlideRecord('kb_knowledge');
kb.autoSysFields(false);
kb.setWorkflow(false);
kb.addQuery('sys_id', kbSysid);
kb.query();
if (kb.next()) {
kb.kb_knowledge_base = TARGET_KB_SYS_ID;
kb.kb_category = TARGET_KB_CATEGORY;
kb.update();
gs.info('Moved ' + kbSysid + ' to Knowledge Base ' + TARGET_KB_SYS_ID);
} else {
gs.info('Did not find ' + kbSysid);
}
}The sys_id's in the script above relate to versions 1 and 2 of the same knowledge article, both had their knowledge base and category updated after running.
