Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Warning message associated with groups

Polyanna Silva
Tera Contributor

I need to insert a warning and blocking message associated with specific groups. How can I do this?
Currently I'm using Business Rules, but I haven't implemented them correctly.

4 REPLIES 4

SanjivMeher
Mega Patron
Mega Patron

When do you want to show the warning or block message?

It depends on your use case. You can use Business Rule or Client Script to show the message.

Also if you can post the current BR script you have?


Please mark this response as correct or helpful if it assisted you with your question.

The message needs to be displayed when a specific group is selected; the script I created is associated with both input and output groups.
I'll send the standard script:
(function executeRule(current, previous /*null when async*/) { var allowedGroups = ['Group A', 'Group B', 'Group C']; var destinationGroups = ['Group D', 'Group E', 'Group F']; if (destinationGroups.indexOf(current.assignment_group.name) > -1 && allowedGroups.indexOf(previous.assignment_group.name) === -1) { gs.addErrorMessage('You do not have permission to assign to this group.'); current.assignment_group = previous.assignment_group; // Reverts the change } })(current, previous);


I didn't do it through the Client Script because it's associated with a catalog item, and I need it to be associated with a group.



I dont see any issue. I would just change this to 

allowedGroups.indexOf(previous.assignment_group.name) == -1

== instead of ===

 

Also this should be an onBefore BR Update incase you have it set as onAfter


Please mark this response as correct or helpful if it assisted you with your question.

Hi @Polyanna Silva ,

 

Correct Business Rule Setup

Here’s how you can adjust your script:

  1. Trigger Conditions
    • Table: task (or incident, change, etc. depending on where assignment groups are used).
    • When: before update (so you can block the change before it’s saved).
    • Condition: assignment_group changes.

Script Example

(function executeRule(current, previous /*null when async*/) {

 

    var allowedGroups = ['Group A', 'Group B', 'Group C'];

    var destinationGroups = ['Group D', 'Group E', 'Group F'];

 

    var prevGroup = previous.assignment_group.getDisplayValue();

    var newGroup = current.assignment_group.getDisplayValue();

 

    // Check if new group is restricted AND previous group is not allowed

    if (destinationGroups.indexOf(newGroup) > -1 && allowedGroups.indexOf(prevGroup) === -1) {

        gs.addErrorMessage('You do not have permission to assign to this group.');

        current.setAbortAction(true); // stops the update

    }

 

})(current, previous);

Key Fixes

  • Use getDisplayValue() instead of .name — safer because assignment_group is a reference field.
  • Use current.setAbortAction(true) instead of reverting the value. This blocks the save entirely, which is cleaner.
  • Keep the rule as Before Update so the error message shows and the transaction is stopped.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Best,

Anupam.