Populate the reference variables on the catalog item level.

LaraReddy
Tera Guru

Hi All,

We do have a catalog item with two Reference type variables.

Now if on the first variable if we select any group then on the second variable level we need list out above selected group users.

Advance thanks.

Note: We tried the auto populate related section on the second variable level but it's not working.

Version = Washington DC.

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @LaraReddy ,

 

You can configure like below.

RunjayPatel_0-1731074227207.png

 

Script include code:

var userUtils = Class.create();
userUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getGroupMembers: function(group) {
		gs.log('Runjay'+group);
		var sysId=[];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', group);
        gr.query();
        while (gr.next()) {
            sysId.push(gr.user.sys_id);
        }
        return 'sys_idIN'+sysId;
    },
    type: 'userUtils'
});

RunjayPatel_2-1731074352772.png

 

Output.

RunjayPatel_1-1731074281258.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

 

 

 

View solution in original post

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @LaraReddy 

 

Look like you are referring to Parent -child relationship. 

 

https://www.servicenow.com/community/developer-forum/how-to-populate-group-values-or-group-members-b...

 

https://community.servicenow.com/community?id=community_question&sys_id=f303339cdbc6b340feb1a851ca96...

https://community.servicenow.com/community?id=community_question&sys_id=148ce6dddbf45c90190dfb243996...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Amit Verma
Kilo Patron
Kilo Patron

Hi @LaraReddy 

 

Assuming you have userGroup variable in your catalog item, you can make use of Advanced Reference Qualifier to populate group users -

javascript:'group='+current.variables.userGroup;

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

LaraReddy
Tera Guru

Hi ,
Thanks for the response.

We created below script include on Global application level and called the same on VA application level.

var getGroupMembers = Class.create();
getGroupMembers.prototype = {
    initialize: function() {},

    getGroupUser: function(groupName) {


        var memberIds = [];
        var members = new GlideRecord('sys_user_grmember');
        members.addQuery('group',groupName);
        members.query();

        while (members.next()) {
           
      memberIds.push(members.getValue('user'));
        }
        
        return memberIds;
},
type: 'getGroupMembers'
}



Under second variable reference qualifier level we called as: 
 
javascript: new global.getGroupMembers().getGroupUser(current.variables.assignment_group);


Note: First variable referred to Group table and second variable referred to Group members table.


But still not listing the users , Could you please check the script and let us know.

Advance thanks.

@LaraReddy 

 

You can refer below post for the Script Include code. Please note that the Script Include should be client callable. 

https://www.servicenow.com/community/developer-forum/com-glide-script-rhinoecmaerror-quot-class-quot...

 

Though I will still recommend you the use the Advanced Reference Qualifier which I shared above. It will be more easy to implement.

javascript:'group='+current.variables.assignment_group;

Please mark this response as correct and helpful if it assisted you with your question.