
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 05:00 AM
Hi community,
I need to write a business rule to check in the change request there's a related list called incidents resolved, so in the change type is emergency I need only p1 and p2 incidents to be selected can someone suggest the business rule so that this scenario can work
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 05:35 AM
Hi @Community Alums ,
So, when you update the related list, it's actually associating the change on the incident record.
So, write the business rule on Incident table.
Before - Update
Conditions,
< Field which stores the change number on the incident when associated from change request > < Changes>
GlideRecord the Change table
Query the change record,
If the change is Emergency
Nested If the current incident is P1 or P2
Else
Abort the action.
Hope this helps.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 05:22 AM
Hi @Community Alums Try below code on Before Insert Update BR on Change Request table
(function executeRule(current, previous /*null when async*/) {
if (current.type == 'Emergency') {
var resolvedIncidents = new GlideRecord('incident');
resolvedIncidents.addQuery('change_request', current.sys_id);
resolvedIncidents.addQuery('priority', 'IN', '1,2');
resolvedIncidents.query();
var validIncidents = true;
while (resolvedIncidents.next()) {
if (resolvedIncidents.priority != '1' && resolvedIncidents.priority != '2') {
validIncidents = false;
break;
}
}
if (!validIncidents) {
gs.addErrorMessage('For Emergency change requests, only P1 and P2 incidents are allowed.');
current.setAbortAction(true); // Prevents saving if validation fails
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 05:35 AM
Hi @Community Alums ,
So, when you update the related list, it's actually associating the change on the incident record.
So, write the business rule on Incident table.
Before - Update
Conditions,
< Field which stores the change number on the incident when associated from change request > < Changes>
GlideRecord the Change table
Query the change record,
If the change is Emergency
Nested If the current incident is P1 or P2
Else
Abort the action.
Hope this helps.
Regards,
Najmuddin.