Issue with the Business rule , how can I fix the code ?

Pooja Khatri
Tera Contributor

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 ?

14 REPLIES 14

It shouldn't allow that.

kkrushkov_0-1712737285347.png

 

Hi @kkrushkov - I am using the before "Insert & Update" Business rule should I make changes to that part ?

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.

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 .

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.