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-10-2024 01:22 AM
It shouldn't allow that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 01:24 AM
Hi @kkrushkov - I am using the before "Insert & Update" Business rule should I make changes to that part ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 01:29 AM
No, you shouldn't.
Review the script once more and inspect for any business rules that might influence its behavior. If you find any, verify their order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 01:40 AM
Hi @kkrushkov - I checked , there are only 4 business rule running on the table and there's no dependency of the Business rules on one another but still the script is not working .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 02:09 AM
Could you please provide additional information that might be helpful? I can't think of why it wouldn't work based on the information I have so far.