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.

Catalog item : Assigned to depended on assignment group variable

Chirag Pathak
Tera Contributor

Hi community,

 

I have a requirement where I have record producer which has two variable. Variable 1 the user has to select to the assignment group and in variable 2 they have to choose the assigned to. I need group members of assignment group selected in variable 1 to be shown to the users how do I do that?

1 ACCEPTED SOLUTION

ProdiptoL
Tera Expert

Hi @Chirag Pathak 

Variable 1 : Assignment Group [assignment_group] --> This will be a reference type variable which will refer to the Goup [sys_user_group] table.

 

Variable 2: Assigned to [assigned_to] --> This will be a 'List Collector' type field. This field will be refer to the User [sys_user] table.

 

Solution: In the advance reference qualifier of the variable 2 call a script include and pass the selected group's sys_id [current.variables.assignment_group]. Write the script in the script include to query the Group Member [sys_user_grmember] table with the selected group id and create an array of sys_ids of the users present against the group in the Group Member table. return the query as "sys_idIN"+array.join(",");

 

I hope this answer will help you.

View solution in original post

6 REPLIES 6

ProdiptoL
Tera Expert

Hi @Chirag Pathak 

Variable 1 : Assignment Group [assignment_group] --> This will be a reference type variable which will refer to the Goup [sys_user_group] table.

 

Variable 2: Assigned to [assigned_to] --> This will be a 'List Collector' type field. This field will be refer to the User [sys_user] table.

 

Solution: In the advance reference qualifier of the variable 2 call a script include and pass the selected group's sys_id [current.variables.assignment_group]. Write the script in the script include to query the Group Member [sys_user_grmember] table with the selected group id and create an array of sys_ids of the users present against the group in the Group Member table. return the query as "sys_idIN"+array.join(",");

 

I hope this answer will help you.

Variable 2 can be a reference type field it is up to your need if you want to select 1 user or multiple user.

Hi ProdiptoL,

 

I have created the script include and passed it to the reference qualifier

 

var <scriptIncludeName> = Class.create();
<scriptIncludeName>.prototype = {
    initialize: function refqualassignedto() {
        var group = current.variables.assignment_group; // your assignment group variable name
        var user_array = [];
        if (group != '') {
            var getMembers = new GlideRecord('sys_user_grmember');
            getMembers.addQuery('group', group);
            getMembers.query();
            while (getMembers.next())
            {
                user_array.push(getMembers.user);
            }
            return 'sys_idIN' + user_array.toString();
        } else {
            return 'active=true';
        }
    },
    type: '<scriptIncludeName>'
};

 

and the reference qualifier looks like

javascript&colon;<scriptIncludeName>();

 

does it need variable attribute?

Hi @Chirag Pathak 

 

Reference Qualifier= javascript&colon;new <scriptIncludeName>().refqualassignedto();

script include correction:

user_array.push(getMembers.getValue("user"));