Checkout multiple kb articles

Steven Chaparro
ServiceNow Employee

Hello,

Before I begin, my ServiceNow version is London patch 6B

I have more than 500 published kb articles in the knowledge base. Now I would like to create a new Knowledge Base just for a portal. Let's say that my new Knowledge base will be called "Portal Knowledge". 
Now I would like to move 25% of the published articles from the Knowledge base to the new Portal Knowledge. Because these articles are already published I cannot make any change. I would need to go to the article and click on the checkout button and then I am able to change the knowledge base on the new version created and publish it again.
My question is, is there a way where I can do all this with a script? Changing the field is easy, but I am struggling how to perform the Checkout action and then publish it again for each article from a script. Any advice or suggestion will be appreciated.

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron

You don't need to checkout since they are already published.

you can just migrated KB articles to new knowledge base.

 

Following  fix script should help you

 

execute();
function execute(){
	try{
		var gr = new GlideRecord('kb_knowledge');
		
		gr.addEncodedQuery('workflow_stateINpublished^kb_knowledge_base=dfc19531bf2021003f07e2c1ac0739ab');
		gr.query();
		while(gr.next()){
			gr.kb_knowledge_base = 'aea036e64f01f740dc984da28110c79b';
			gr.update();
		}
	}
	catch(exception){
		gs.log("Exception in KB  migration script:"+exception);
	}
}

 

Regards,

Sachin

View solution in original post

2 REPLIES 2

sachin_namjoshi
Kilo Patron

You don't need to checkout since they are already published.

you can just migrated KB articles to new knowledge base.

 

Following  fix script should help you

 

execute();
function execute(){
	try{
		var gr = new GlideRecord('kb_knowledge');
		
		gr.addEncodedQuery('workflow_stateINpublished^kb_knowledge_base=dfc19531bf2021003f07e2c1ac0739ab');
		gr.query();
		while(gr.next()){
			gr.kb_knowledge_base = 'aea036e64f01f740dc984da28110c79b';
			gr.update();
		}
	}
	catch(exception){
		gs.log("Exception in KB  migration script:"+exception);
	}
}

 

Regards,

Sachin

Steven Chaparro
ServiceNow Employee

Awesome! This was exactly what I was looking for. I was able to migrate the articles with a specific encoded query. Thank you very much!!