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.

based on group want to display service accounts

srikanthr066535
Tera Contributor

There are 2 variables in catalog form one is group and 2 is service account based on selected group i need to show service accounts which are present in selected group. And also want to check if the requested for is the manager of the group them RITM should auto-approve else it should go the group maanger approval.

8 REPLIES 8

J Siva
Kilo Patron
Kilo Patron

Hi @srikanthr066535 
1. Create one script include as below to get the group members list.

var SJCatalogUtils = Class.create();
SJCatalogUtils.prototype = {
    initialize: function() {},
    getUsers: function(groupId) {
        var userArr = [];
        var grp_member = new GlideRecord('sys_user_grmember');
        grp_member.addQuery('group', groupId);
        grp_member.addEncodedQuery('user.nameLIKEService Account');
        grp_member.query();
        while (grp_member.next()) {
            userArr.push(grp_member.user.sys_id);
        }
		return 'sys_idIN'+userArr.toString();

    },

    type: 'SJCatalogUtils'
};

JSiva_0-1747979514376.png

2. Use "Advanced Reference qualifier" to fetch the service accounts by passing the group sys_id from the previous variable.

javascript: new global.SJCatalogUtils().getUsers(current.variables.select_group);

JSiva_1-1747979657764.png

 

Regarding the auto-approval process, before triggering the approval, use a script action if you're working with a workflow, or an "if" condition if you're using Flow Designer, to verify that group.manager == requested_for.

Regards,
Siva

 

Service account is a true/false field if it is true then i need to show in service account 

Ankur Bawiskar
Tera Patron
Tera Patron

@srikanthr066535 

so you want group members in 2nd variable and 2nd variable is referring to sys_user?

If yes then you can use this in advanced ref qualifier

javascript: var query = '';
var arr = [];
var memberRec = new GlideRecord('sys_user_grmember');
memberRec.addQuery('group', current.variables.groupVariableName);
memberRec.addEncodedQuery('user.nameLIKEService Account'); // give your encoded query here
memberRec.query();
while (memberRec.next()) {
    arr.push(memberRec.getValue('user'));
}
query = 'sys_idIN' + arr.toString();
query;

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

Yes it's a reference to Group member if i select any group in Group field i want to show service account which are present in that group Service account is a True/false field in user table