Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Show more results as Catalog Item Variable for specific group

AdamUMC
Tera Guru

Hi,

I have a catalog item variable that references "cmdb_ci_business_app".

Now, I want that variable to only show results that:
1. Are Active
2. Have the status "In Production"
3. Managed By Group, which must be one of the groups the person is a member of

If the person is a member of a specific group, say "SpecialGroup", then point 3 can be omitted.

How can I easily achieve this? I've tried several solutions, but nothing works.

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@AdamUMC 

try this in advanced ref qualifier on that variable

-> ensure you replace your correct group name

-> ensure you replace : with : as there is a known issue when we reply in community it converts that character

javascript: var query = '';
if (gs.getUser().isMemberOf('SpecialGroup'))
    query = 'active=true^install_status=1';
else {
    var groupsArr = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
    query = 'active=true^install_status=1^managed_by_group.sys_idIN' + groupsArr.toString();
}
query;

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@AdamUMC 

Glad to know that my script worked.

yes getMyGroups() will show parent group also

for handling that you need to query sys_user_grmember and get exact group for that user

-> ensure you replace your correct group name

-> ensure you replace : with : as there is a known issue when we reply in community it converts that character

javascript:
var query = '';
if (gs.getUser().isMemberOf('SpecialGroup'))
    query = 'active=true^install_status=1';
else {
    var groupsArr = [];
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", gs.getUserID());
    gr.query();
    while (gr.next()) {
        groupsArr.push(gr.getValue('group'));
    }
    query = 'active=true^install_status=1^managed_by_group.sys_idIN' + groupsArr.toString();
}
query;

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks @Ankur Bawiskar!

Sorry for the late reply, was a few days away. The first advanced reference qualifier works great. The second one, I will keep in mind. I'm sure I will need it again.

Best regards,