Update parent of a child kb article if parent version is outdated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 09:13 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 11:05 PM
Hi @Gopal6
I think that is OOB available in instance as per below thread:-
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 11:54 PM
@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
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
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:20 AM
Hi,
Thanks for the reply. I have tried this but child article still shows outdated parent article. Do u know what is missing here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:30 AM
@Gopal6 Try below updated code.
ServiceNow Community Rising Star, Class of 2023