I want to implement a case in which incident should not get saved unitl and unless a kb is attached
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2025 11:51 PM
//This should be only when assignment group is service desk.
//Here's the code I have written but when using this , it is throwing the error even after attaching the kb
function onSubmit() {
var kb=g_form.getValue('knowledge_base');
var assignmentGroup = g_form.getDisplayValue('assignment_group');
if (assignmentGroup && assignmentGroup.toLowerCase() ==='service desk'){
if (!kb){
g_form.addErrorMessage('You must attach a <b>Knowledge Base</b> before saving this incident');
return false;
}
}
return true;
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @PriyanshuS64936 ,
Your logic to check if Assignment Group is Service Desk then check if KB is attached or not then show error message is not quite right.
so try Business rule on incident table .
When to run: Before, Insert and Update true
Condition: Assignment Group is Service Desk or Assignment Group changes to Service Desk and State is No closed or Resolved
Advance:
var kbAttached = false;
var grKB = new GlideRecord('m2m_kb_task');
grKB.addQuery('task', current.sys_id);
grKB.query();
if (grKB.hasNext()) {
kbAttached = true;
}
// If no KB is attached, abort the action and show an error message
if (!kbAttached) {
current.setAbortAction(true);
gs.addErrorMessage('You must attach at least one Knowledge Article before setting the incident to ' + current.state.getDisplayValue() + '.');
}
If this information proves useful, kindly mark it as helpful or accepted solution.
Thanks,
BK
