Update parent of a child kb article if parent version is outdated.

Gopal6
Tera Contributor

Hi,

 

I have an requirement where the parent of child kb article should be updated to published version of parent kb article when parent kb article version is outdated. How can I achieve this?

 

Thanks,

 

Gopal 

5 REPLIES 5

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Gopal6 

I think that is OOB available in instance as per below thread:-

https://www.servicenow.com/community/knowledge-managers/the-parent-field-on-the-child-article-is-get... 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

jaheerhattiwale
Mega Sage
Mega Sage

@Gopal6 Enable "Knowledge Management Advanced Installer" plugin if not already installed. This will activate the versioning on articles.

 

Please write below Business Rule on kb_knowledge table

 

jaheerhattiwale_2-1670053947483.png

 

jaheerhattiwale_3-1670053969703.png

 

 

Script:

(function executeRule(current, previous /*null when async*/) {

//Get all the child articles of outdated article
var knowledge = new GlideRecord("kb_knowledge");
knowledge.addQuery("parent="+current.sys_id.toString());
knowledge.query();

while(knowledge.next()){
//Get the last published version of outdated article
var publishedArticle = new GlideRecord("kb_knowledge");
publishedArticle.addQuery("workflow_state=published");
publishedArticle.orderByDesc("sys_updated_on");
publishedArticle.query();

if(publishedArticle.next()){
//If any published version article for outdated article is found the set it as parent of child article
knowledge.parent = publishedArticle.sys_is.toString();
knowledge.update();
}
}

})(current, previous);

 

 

Please mark as correct answer if this solves your problem

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi, 

Thanks for the reply. I have tried this but child article still shows outdated parent article. Do u know what is missing here?

@Gopal6 Try below updated code.

 

(function executeRule(current, previous /*null when async*/) {

//Get all the child articles of outdated article
var knowledge = new GlideRecord("kb_knowledge");
knowledge.addQuery("parent="+current.sys_id.toString());
knowledge.query();

while(knowledge.next()){
//Get the last published version of outdated article
var publishedArticle = new GlideRecord("kb_knowledge");
publishedArticle.addQuery("workflow_state=published");
publishedArticle.addQuery("number="+knowledge.number.toString());
publishedArticle.orderByDesc("sys_updated_on");
publishedArticle.query();

if(publishedArticle.next()){
//If any published version article for outdated article is found the set it as parent of child article
knowledge.parent = publishedArticle.sys_id.toString();
knowledge.update();
}
}

})(current, previous);
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023