Business Rule: update additional comments with assignment group when it changes

JP-ODU
Tera Guru

I've been trying to get this script working, but I'm clearly getting something (or multiple somethings) wrong.

 

Goal: if the assignment group on an Incident is updated, then update additional comments saying "This ticket has been assigned to [assignment group selected]"

 

Table: Incident

Active: True

Advanced: True

before Update

Filter conditions: Assignment group | changes AND Assignment group | is not empty

 

Script:

(function executeRule(current, previous) {
  // Get the assignment group information
  var assignedGroup = new GlideRecord('assignment_group');
  if (assignedGroup.get(current.assignment_group)) {
    var assignmentGroup = assignedGroup;
    
    // Add a comment with the assignment group
    var comment = 'The ticket has been updated. Assigned to: ' + assignmentGroup;
    current.comments = comment;
  }
})(current, previous);

Can anyone see how to fix this?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

In a GlideRecord, the value in quotes following is a table name.  assignment_group is not the name of a table, so this should be replaced with sys_user_group, but since Business Rules run on the server, you can dot-walk to the name of the group, so don't even need a GlideRecord.  Your script can simply be:

(function executeRule(current, previous) {
    // Add a comment with the assignment group
    var comment = 'The ticket has been updated. Assigned to: ' + current.assignment_group.name;
    current.comments = comment;
})(current, previous);

 

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

In a GlideRecord, the value in quotes following is a table name.  assignment_group is not the name of a table, so this should be replaced with sys_user_group, but since Business Rules run on the server, you can dot-walk to the name of the group, so don't even need a GlideRecord.  Your script can simply be:

(function executeRule(current, previous) {
    // Add a comment with the assignment group
    var comment = 'The ticket has been updated. Assigned to: ' + current.assignment_group.name;
    current.comments = comment;
})(current, previous);

 

jMarshal
Mega Sage
Mega Sage

I don't think that script is doing what you need it to...you don't need any glide here.

var curAssgnGroup = current.assignment_group;

var prevAssgnGroup = previous.assignment_group;

 

if (curAssgnGroup != prevAssgnGroup) {

 

current.comments = "The ticket has been updated. Assigned to: ' + curAssgnGroup;

}

I found where I was misplacing parentheses and now have it *almost* working... Using the below script gets me the sysID of the assignment group, not it's name? How do I fix that?

 

(function executeRule(current, previous) {
var curAssgnGroup = current.assignment_group;
var prevAssgnGroup = previous.assignment_group;
if (curAssgnGroup != prevAssgnGroup) {
current.comments = "The ticket has been updated. Assigned to"  + curAssgnGroup;
}
})(current, previous);

Use the right answer, previously provided.  You don't need the current vs previous comparison in the script since you have the Filter conditions on the When to run tab.