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.

current.setAbortAction(true) doesn't work if nothing is changed to the incident record

natecousins
Tera Contributor

I have a "before" Business Rule to prevent an update to an incident record if the 'Assigned to' user is not a member of the 'Assignment Group'. The BR only runs on 'Update', but only seems to work if you modify the record like change the value of a field. If you do not make any changes, the BR will not work.

I have set the Order field to 1 and to the low number like 10,000. Still doesn't work. I have added current.setWorkflow(false), and it still doesn't work.

The conditions are: assigned_to is not empty AND assignment_group is not empty

find_real_file.png

CODE:

(function executeRule(current, previous /*null when async*/) {
// Add your code here
var assigned_to = current.assigned_to;
var assignment_group_display = current.assignment_group.getDisplayValue().trim();
var assigned_to_display = current.assigned_to.getDisplayValue().trim();
var userObj = '';

userObj = gs.getUser().getUserByID(assigned_to);

if (!userObj.isMemberOf(assignment_group_display)) {
var msg = gs.getMessage('ERROR: ' + assigned_to_display + ' is not a member of ' + assignment_group_display + '. Please ensure the "assigned to" user is a member of the "assignment group".');

current.setAbortAction(true);
current.setWorkflow(false); 
gs.addErrorMessage(msg);
}

})(current, previous);

 

Any thoughts why?

21 REPLIES 21

I didn't see the code has some other issues as well.

 

Try the following, 

 

Remove the condition related to Assigned_to.

Update the script to this.

if (!gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())) { 
var msg = gs.getMessage('ERROR: ' + assigned_to_display + ' is not a member of ' + assignment_group_display + '. Please ensure the "assigned to" user is a member of the "assignment group".');


gs.addErrorMessage(msg); 

current.setAbortAction(true);
}

I appreciate the help, but this didn't work. 😞

natecousins
Tera Contributor

Perhaps this little nugget of info will help out too. I just now noticed that the record is not being updated in the scenario of my original post. I just checked the timestamp in the updated field. I assumed the record was still being updated because when I clicked 'Save', the page just refreshes without showing the error message.

 

Hi there,

 

gs.addinfomessage is coming in a different window. I have seen this working in my personal instance. Also, This is a bug in ServiceNow Kingston Release.

Let me know your findings.

 

Best Regards,

Rahul

This is helpful info and might be the issue I'm experiencing. If it's indeed a bug, I can live with the current behavior until it gets fixed. I'll need to perform more tests though.