Throw an error message if two INCTASK has same assignment group under the Parent Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Requirement:
For a given Parent Incident, the system must ensure that no two Incident Tasks (INCTASK) have the same Assignment Group.
Behavior:
- When a user attempts to create or update an Incident Task with an Assignment Group that already exists on another Incident Task under the same Parent Incident, the system must:
- Prevent the record from being saved.
- Display an error message informing the user that an Incident Task already exists for that Assignment Group under the same Parent Incident.
- Display the existing Incident Task number and link in the error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello @SanikaK ,
Example:
If this response was helpful, please consider marking it as Correct and Helpful. You may mark more than one reply as an accepted solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
this is an easy requirement.
what did you start and where are you stuck?
Unless you start you won't learn.
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
(function executeRule(current, previous /*null when async*/ ) {
if (!current.parent || !current.assignment_group) {
return;
}
var gr = new GlideRecord('u_incident_task');
gr.addQuery('parent', current.parent);
gr.addQuery('assignment_group', current.assignment_group);
gr.addQuery('sys_id', '!=', current.sys_id); // exclude current record
gr.query();
if (gr.next()) {
var instanceURL = gs.getProperty('glide.servlet.uri');
var link = instanceURL + 'incident_task.do?sys_id=' + gr.getUniqueValue();
var msg = "An Incident Task already exists for this Assignment Group.\n";
msg += "Task Number: " + gr.getValue('number') + "\n";
msg += "Link: " + link;
gs.addErrorMessage(msg);
current.setAbortAction(true); //
}
})(current, previous);
I have written this code but not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @SanikaK
You can start with a Before Insert/Update Business Rule on the incident_task table. This approach ensures the validation occurs server-side before the record is saved to the DB.
Trigger condition could be:
Assignment Group - Changes OR
Parent - Changes
Sample code :
if (current.assignment_group.nil() || current.incident.nil()) {
return;
}
var incTask = new GlideRecord('incident_task');
incTask.addQuery('incident', current.incident); // parent incTask.addQuery('assignment_group', current.assignment_group);
incTask.query();
if (incTask.next()) {
var message = 'An Incident Task already exists for this Assignment Group (' + incTask.assignment_group.getDisplayValue() + ') under the Parent Incident';
gs.addErrorMessage(message);
current.setAbortAction(true); }
