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

Brad Bowman
Mega Patron

You need to use an Advanced Reference Qualifier that calls a Script Include.  The SI will use GlideRecord to query the referenced table to return records that meet 1. and 2., then for each record that meets 3, push the sys_id to an array.  The return from the SI will be like 'sys_idIN' then the comma-separated joined array.  There are many examples of this.  Give it a shot and post your reference qualifier and script if you get stuck.

AdamUMC
Tera Guru

Thanks @Brad Bowman  ,

I have already tried this once, but unfortiunately it didn't work properly.
Will try agai and post here script include and advanced reference qual.

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

Thanks @Ankur Bawiskar!
This works fantastic and is pretty simple!

Is it also possible to ignore the Parent groups of the groups that are set in the "managed_by_groups" of "cmdb_ci_business_app" items? Because now they are included in the overview of this variable.

People are often not directly members of the Parent groups, but indirectly through the Parent-Child relationship between them.

I only want results of which the people are actually directly members of the group(s). Thanks again!