logo

NJP

Catalog items - Make Assigned to dependent on Assignment group

Import · Nov 20, 2021 · article

image

From the past couple of months, I have seen quite a few questions around making assigned to variable dependent on assignment group variable on catalog item or record producer. Its quite simple but it requires some platform and scripting knowledge.

There could be many approaches to achieve this simple task but below is how I and many of us would do it.

For the sake of demonstration, I have already created a sample item with two reference type variables; Assigned to [assigned_to] and Assignment Group [assignment_group].

Assignment group variable doesn't require any special configuration. However, we will need to apply advance reference qualifier on the assigned_to variable by following the below steps.

Problem Statement

When user select Assignment group on the form then Assigned to field must show filtered list of users that belongs to Selected Assignment group only

Solution

Step 1

Open the Assigned to variable and go to Type specifications tab and set the following values.

User Reference Qualifier - Advance

Reference Qualifier

Global Scope

javascript: filterAssignedTo(current.variables.assignment_group);

Scoped App

javascript: <scope_id>.filterAssignedTo(current.variables.assignment_group);

Variable attributes - ref_qual_elements=assignment_group

Screenshot for reference

image

Step 2

Create a script include with below configuration.

Name - filterAssignedTo

Script

function filterAssignedTo(group) {

    var users = [];

    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. 
    }

}

Voila that's it!

Output

Filtered list of users based on the assignment group selected.

image

Hope you found it helpful. If so, why don't you bookmark it for future, hit helpful and give feedback in the comment box below.

Regards,

Muhammad

View original source

https://www.servicenow.com/community/developer-articles/catalog-items-make-assigned-to-dependent-on-assignment-group/ta-p/2302782