- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 07:44 AM
Hi , can someone please help with a script that would prevent duplicate creation of a Knowledge Article at the time of publishing if the short description is same. If any one use insert and insert stay button the copy of the article would get created and will get saved as a draft, but if there is any existing article with same short description the user will not get it published, it should through an error message like in the script.
(function executeRule(current, previous /*null when async*/) { var incidentShortDesc = current.getValue('short_description'); //considering short_desr to be the key , you can use any fieldwhich you wanted to check var kbArticleGr = new GlideRecord('kb_knowledge'); kbArticleGr.addQuery('short_description', incidentShortDesc); kbArticleGr.query(); if (kbArticleGr.hasNext()) { gs.addErrorMessage('A knowledge article with the same short description already exists.'); current.setAbortAction(true); } })(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 08:02 AM
You can use below code
var incidentShortDesc = current.getValue('short_description');
var kbArticleGr = new GlideRecord('kb_knowledge');
kbArticleGr.addEncodedQuery('sys_id!='+current.sys_id);
kbArticleGr.addQuery('short_description', incidentShortDesc);
kbArticleGr.query();
if (kbArticleGr.hasNext()) {
gs.addErrorMessage('A knowledge article with the same short description already exists.');
current.setAbortAction(true);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 08:02 AM
You can use below code
var incidentShortDesc = current.getValue('short_description');
var kbArticleGr = new GlideRecord('kb_knowledge');
kbArticleGr.addEncodedQuery('sys_id!='+current.sys_id);
kbArticleGr.addQuery('short_description', incidentShortDesc);
kbArticleGr.query();
if (kbArticleGr.hasNext()) {
gs.addErrorMessage('A knowledge article with the same short description already exists.');
current.setAbortAction(true);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------