logo

NJP

How to migrate from V2 to V3 of knowledgebase

Import · Apr 13, 2017 · article

Hey Guys, i have been doing a good amount of work on migrating knowledgebase from V2 to V3 and have captured steps on how to do that.

Steps:

Take a backup of all article from kb_knowledge table in xml format from the source instance

Take a backup of kb_category table from the source instance.

Import kb_knowldge_base.xml to kb_knowledge_base table using import xml option to target instance.

Import kb_category.xml to kb_category table using import xml option to target instance.

background script : setZzFullCategory(); // Optional depending on the knowledge bases in question , use it if you have more than one v3 knowledgebase.

background script : moveArticles('','',false); - Get count of articles that will be moved.

background script : moveArticles('','',true); - Move articles to Knowldge base v3

background script : updateV3Category('kb_sys_id',false); - Get count of articles that will be moved. (repeat this for all v3 knowledgebases)

background script : updateV3Category('kb_sys_id',true); - Update category for the articles. (repeat this for all v3 knowledgebases)

background script : publishArticles('kb_sys_id',false); -- Get count of articles that will be updated. // Optional step (repeat this for all v3 knowledgebases)

background script : publishArticles('kb_sys_id',true); - attach workflow for the articles. (This may take around 3 to 4 mins to complete); // Optional step (repeat this for all v3 knowledgebases)

Verify if the knowledgebase modules on left nav point to $knowledge.do else point them to $knowledge.do

script includes mentioned above

Name: setZzFullCategory

script:

function setZzFullCategory() {

var gr = new GlideRecord('kb_category');

gr.orderBy('sys_id');

gr.query();

while(gr.next()) {

if(gr.parent_table =='kb_knowledge_base') {

gr.u_zz_full_category = gr.parent_id.title + " / " + gr.full_category;

gr.setWorkflow(false);

gr.autoSysFields(false);

gr.update();

}

else {

if(gr.parent_id.parent_id.parent_id != undefined) {

gr.u_zz_full_category = gr.parent_id.parent_id.parent_id.title + " / " + gr.full_category;

gr.setWorkflow(false);

gr.autoSysFields(false);

gr.update();

}

else {

if(gr.parent_id.parent_id !=undefined) {

gr.u_zz_full_category = gr.parent_id.parent_id.title + " / " + gr.full_category;

gr.setWorkflow(false);

gr.autoSysFields(false);

gr.update();

}

else {

if(gr.parent_id !=undefined) {

gr.u_zz_full_category = gr.parent_id.title + " / " + gr.full_category;

gr.setWorkflow(false);

gr.autoSysFields(false);

gr.update();

}

}

}

}

}

}

Name: moveArticles

Usage:

moveArticles(,,false); This line would check how many records would be migrated from source to destination KB

moveArticles(,,true); This le will do the actual migration of KB articles.

script:

function moveArticles(source,destination,doIt) {

if(doIt == undefined) {

doIt = false;

}

var i = 0;

var query = 'kb_knowledge_base='+ source;

var grKb = new GlideRecord('kb_knowledge');

grKb.addEncodedQuery(query);

grKb.query();

while(grKb.next()) {

if(doIt) {

grKb.kb_knowledge_base = destination;

grKb.update();

}

i++;

}

if(doIt) {

sDebug = 'Number of KB articles that got migrated: ' + i;

}

else {

sDebug = 'Number of KB articles that would be migrated: ' + i;

}

gs.log(sDebug,'fpadmin');

}

Name: updateV3Category

Usage: updateV3Category(,true);

Script:

function updateV3Category(source, doIt) {

if(doIt == undefined) {

doIt = false;

}

var i = 0;

var sDebug = '';

var kcquery = '';

var category = '';

var query = 'kb_knowledge_base='+ source;

var grKb = new GlideRecord('kb_knowledge');

grKb.addEncodedQuery(query);

grKb.query();

while(grKb.next()) {

category = '';

kcquery = 'parent_id=' + source + 'label=' + grKb.topic ;

if(doIt) {

var grKc = new GlideRecord('kb_category');

grKc.addEncodedQuery(kcquery);

grKc.query();

if(grKc.next()) {

category = grKc.sys_id;

}

grKb.kb_category = category;

grKb.update();

}

i++;

sDebug += " " + kcquery;

}

if(doIt) {

sDebug += 'Number of KB articles that got updated with new category: ' + i;

}

else {

sDebug += 'Number of KB articles that would be updated with new category: ' + i;

}

gs.log(sDebug,'fpadmin');

}

Name: publishArticles

Usage:

publishArticles(,false); This gets the number of articles that will be published.

publishArticles(,true); This publishes the articles.

script:

function publishArticles(source,doIt) {

if(doIt == undefined) {

doIt = false;

}

var i = 0;

var query = 'kb_knowledge_base='+ source;

var grKb = new GlideRecord('kb_knowledge');

grKb.addEncodedQuery(query);

grKb.query();

while(grKb.next()) {

if(doIt) {

grKb.workflow_state = 'draft';

grKb.update();

new KBWorkflow().startWorkflow(grKb, "workflow");

}

i++;

}

if(doIt) {

sDebug = 'Number of KB articles that got published: ' + i;

}

else {

sDebug = 'Number of KB articles that would be published: ' + i;

}

gs.log(sDebug,'fpadmin');

}

Thanks

Anil

View original source

https://www.servicenow.com/community/in-other-news/how-to-migrate-from-v2-to-v3-of-knowledgebase/ba-p/2270353