Business Rule to copy a list field to another list field

Staxed
Giga Guru

Looking for a little advice.  I have a business rule that is supposed to be updating a list field on one table to the list field on another table.  Both fields setup exactly the same, list types with a reference to the sys_user_group_type table in order to select multiple types.

 

The business rule looks like it's working according to the logs I have added, the log is showing multiple sysids after the business rule runs.  However, on the target table, after the business rule has run, the field only shows the first result in the list (it only ever has one entry in it, even though the log is showing all sysids are being passed).  I'm stuck trying to figure out what is going on at this point.

 

It is a before insert/update business rule set to run when the assignment group changes:

 

 

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

        var groupSysId = current.assignment_group;
        var groupRecord = new GlideRecord('sys_user_group');
        if (groupRecord.get(groupSysId)) {

            var groupTypes = groupRecord.type;
			gs.info("GroupType - Assignment Group Type: " + groupTypes);

            current.u_assignment_group_type = groupTypes;
			gs.info("GroupType - Current Custom Assignment Group Type: " + current.u_assignment_group_type);
        }
})(current, previous);

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Staxed 

if field u_assignment_group_type is list type then use this

(function executeRule(current, previous /*null when async*/ ) {
        // Check if assignment_group is set
        if (current.assignment_group) {
            // Get the sys_id of the assignment group
            var groupSysId = current.assignment_group;
            var arr = [];
            // Query the sys_user_group table to fetch the type field
            var groupRecord = new GlideRecord('sys_user_group');
            groupRecord.addQuery('sys_id', 'IN', groupSysIds);
            groupRecord.query();
            while (groupRecord.next()) {
                arr.push(groupRecord.type.toString());
            }
            // Set the u_assignment_group_type field with the same values
            current.u_assignment_group_type = arr.toString();
        }
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

And it looks like I was just missing an issue with the field this entire time, since the max-length property doesn't show on the form for list types, I didn't see that it was set to 32.  I increased this and now doing it manually, or using both scripts work.  I'll mark your answer as correct though since it does work :D.