Restrict creation of record if one is already present
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 02:07 AM
I have to restrict creation of "Incident_task" record in the related list of incident if one record for the same incident is already present.
i wanted to achieve this requirement by removing the "New" button after creation of one record. so that no one can create more than one record in "Incident_task" related list .
Suppose in the below screenshot , i have crated one record for incident task then just after creation i should not be able to see "New" button to create another task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 02:50 AM
Let's define a Business Rule Before Insert.
You can validate if already existed Incident Task for the Incident.
Sample.
(function executeRule(current, previous /*null when async*/ ) {
var grIncidentTask = new GlideRecord('incident_task');
grIncidentTask.addNotNullQuery('incident');
grIncidentTask.addQuery('incident', current.getValue('incident'));
grIncidentTask.addQuery('sys_id', '!=', current.getUniqueValue());
grIncidentTask.setLimit(1);
grIncidentTask.query();
if (grIncidentTask.next()) {
gs.addErrorMessage(gs.getMessage("Incident Task already exists for this Incident " + current.getValue('incident')));
current.setAbortAction(true);
}
})(current, previous);
Cheers,
Tai Vu