Help with kb_knowledge table query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 07:33 AM
Hi all!
I need help querying the kb_knowledge table on a record producer so I can attach the latest version of a kb article on the incidents it creates.
var kbArt = new GlideRecord('kb_knowledge');
kbArt.addQuery('number', 'KB0107111');
kbArt.orderByDesc('sys_created_on');
kbArt.setLimit(1);
kbArt.query();
if (kbArt.next()) {
var tableRec = new GlideRecord('m2m_kb_task');
tableRec.initialize();
tableRec.kb_knowledge = kbArt.sys_id;
tableRec.task = current.sys_id;
tableRec.insert();
}
Any help is much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 08:07 AM - edited 01-05-2024 08:47 AM
@Magali Legaspi : I used the same script in my PDI, and it worked. Please check if the KB number you are supplying as input is valid. Check if the user to whom you are trying to submit the record producer has access to create entries in the table. I tried with the admin user, and it worked.
If there is other login in your record producer script, please make sure that this piece of code is executing by placing some log statements.
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 08:07 AM
Hello @Magali Legaspi ,
Do you want to attach the article as a attachment or do you wanted to create a new record in m2m_kb_task table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 08:17 AM
- To ensure you are getting the latest version on the KB Article include the 'latest' field in your query. There is no need for the line below, just remove that
kbArt.orderByDesc('sys_created_on');
e.g.
var kbArt = new GlideRecord('kb_knowledge');
kbArt.addQuery('number', 'KB0107111');
kbArt.addQuery('latest', 'true');
kbArt.setLimit(1);
kbArt.query();
if (kbArt.next()) {
var tableRec = new GlideRecord('m2m_kb_task');
tableRec.initialize();
tableRec.kb_knowledge = kbArt.sys_id;
tableRec.task = current.sys_id;
tableRec.insert();
}
Regards
Paul