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

Brian Lancaster
Tera Sage

It is a before update so unless something is changed the business rule will never run.  How is your assigned_to set?  OOB functionality should already prevent users who are not member of the group from being put in the assigned to.  If you go into configure dictionary on the assigned to filed you should see a Dependent Field tab.  It should list assigment_group on that tab.

We do not require that the assignment_group and assigned_to fields be mandatory. And sometimes user fill out the assigned_to field before the assignment_group field.

In my OOB developer instance with the assigned_to dictionary setup the way I mentioned here is what happens for me with neither filed mandatory.

If I update the assigned to first and then change the assignment group if the assigned to is not a member of the group it remove them from the assigned to and if they are a member of the group it leaves them in the assigned to.

That scenario does not occur in our Kingston instance/configuration.

Yes, in the Data Dictionary on the Task table, the assigned_to field is dependent on the assignment_group field. But, if the assigned_to field is populated before the assignment_group field (which is also linked to our Business Service field via assignment lookup rules), it still allows the update to occur if the assigned_to is not a member of the assignment_group.