Issue with the Business rule , how can I fix the code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 10:24 PM
I have a requirement where , I need to prevent an API from being able to have the calculated priority be Sev0.
and it will be done if we implement the below logic
In a single payload, Impact cannot be 1 - High (value = 1) and Urgency cannot be High (value = 1) at the same time.
If Incident Impact is already set to 1 - High and Urgency is set to Medium High or Normal, do not allow the payload to set Urgency to High
If Incident Urgency is already set to High and Impact is set to something other than 1 - High , do not allow the payload to set Impact to 1 - High
I have written the below Business Rule - Before "Insert and Update"
(function executeRule(current, previous /*, gs*/) {
// Check if Impact and Urgency cannot be set to High simultaneously
if (current.impact == 1 && current.urgency == 1) {
gs.addErrorMessage("Cannot set Impact and Urgency to High simultaneously.");
return;
}
// Check if Impact is already set to High and Urgency is Medium High or Normal
if (current.impact == 1 && (current.urgency == 2 || current.urgency == 3)) {
gs.addErrorMessage("Cannot set Urgency to High when Impact is already High.");
return;
}
// Check if Urgency is already set to High and Impact is not High
if (current.urgency == 1 && current.impact != 1) {
gs.addErrorMessage("Cannot set Impact to High when Urgency is already High.");
return;
}
})(current, previous);
But the script is not working and I am not getting expected output on the API side , How can I fix the script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 11:14 PM
Hello, @Pooja Khatri
Try using setAbortAction(true) to abort the action within the if statements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 11:21 PM
Hi @kkrushkov - can you help me with the updated script with the above business rule please .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 11:24 PM
(function executeRule(current, previous /*, gs*/) {
// Check if Impact and Urgency cannot be set to High simultaneously
if (current.impact == 1 && current.urgency == 1) {
gs.addErrorMessage("Cannot set Impact and Urgency to High simultaneously.");
current.setAbortAction(true);
}
// Check if Impact is already set to High and Urgency is Medium High or Normal
if (current.impact == 1 && (current.urgency == 2 || current.urgency == 3)) {
gs.addErrorMessage("Cannot set Urgency to High when Impact is already High.");
current.setAbortAction(true);
}
// Check if Urgency is already set to High and Impact is not High
if (current.urgency == 1 && current.impact != 1) {
gs.addErrorMessage("Cannot set Impact to High when Urgency is already High.");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 01:16 AM
Hi @kkrushkov - I tried with the script , I tried scenario where impact and urgency are set to 1 .
It should have restrict the api from creating incident (POST) but I was able to create incident through API.