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.

How to make "Assign to" dependent on "Assignment Group" in a record producer?

Cory Miller1
Kilo Contributor

We want to limit the user list under "Assigned to" on a record producer based on the selected "Assignment Group"...

20 REPLIES 20

@Cory Miller 

Can you please add some screenshot of your script include and variable configuration ?

find_real_file.png

function filterAssignedTo(group) {
// function filterAssignedTo() {
var users = [];
// var group = '6a0059d42f2130103d48bcb62799b6b6';
if (group != '') {
var getGroupMembers = new GlideRecord('sys_user_grmember');
getGroupMembers.addQuery('group', group);
getGroupMembers.query();
while (getGroupMembers.next()) {
users.push(getGroupMembers.getValue('user'));
}
return 'sys_idIN' + users.toString();
} else {
return 'sys_idIN';
//return 'active=true'; //uncomment this line if you want to return all the active users if assignment group is not selected. Must Comment just above line.
}

}

find_real_file.png

Hi @Cory Miller,

Please try below 

<scope_name>.filterAssignedTo(current.variables.assignment_group);

Please replace <scope_name> with your custom scope name. Also, ensure assignment_group variable is the correct name.

In the scoped application we call script include by its API name instead of name and I believe that's the main issue here. 

 

 

Regards,
Muhammad

Include the API name field value in your reference qualifier?

Quick Demo, this way create your script include. 

 

find_real_file.png

 

in my case, i will call it like this way

 

javascript: new x_43765_aaaa.getAssignTo().filterAssignedTo(current.variables.assignment_group);

 

var getAssignTo = Class.create();
getAssignTo.prototype = {
    initialize: function() {},
    filterAssignedTo: function(group) {
        // function filterAssignedTo() {
        var users = [];
        // var group = '6a0059d42f2130103d48bcb62799b6b6';
        if (group != '') {
            var getGroupMembers = new GlideRecord('sys_user_grmember');
            getGroupMembers.addQuery('group', group);
            getGroupMembers.query();
            while (getGroupMembers.next()) {
                users.push(getGroupMembers.getValue('user'));
            }
            return 'sys_idIN' + users.toString();
        } else {
            return 'sys_idIN';
            //return 'active=true'; //uncomment this line if you want to return all the active users if assignment group is not selected. Must Comment just above line.
        }

    },

    type: 'getAssignTo'
};

Are you referring to the Reference qualifier?

    javascript: x_670770_my_scoped_app.getAssignTo().filterAssignedTo(current.variables.assignment_group); 

 

Where x_670770_my_scoped_app.getAssignTo is the API name.

 

Also, assignment_group & assigned_to are the variable names on the Record Producer

 

But it is still not working for me...