How to get only the 'Groups' of a 'Requested For' user (Service Catalog)

pjftenorio
Tera Expert

Hi, I'm trying to display only the Groups of the Requested User Field in my Service Catalog.

Upon using script - "javascript:'user='+current.variables.requested_for;" it only displays sys_id of Groups how to I display the display value of the Groups?

 

Service Catalog Form: 

pjftenorio_0-1694669935617.png

 

Variable declaration:

pjftenorio_1-1694669947629.png

 

 

2 ACCEPTED SOLUTIONS

@pjftenorio 

there was a type in my above response; it should be IN and not NIN

update as this

javascript: 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.requested_for).getMyGroups());

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

View solution in original post

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @pjftenorio ,

 

Please try below

RAMANAMURTHYG_0-1694676159183.png

your table should be reference to sys_user_group table not sys_user_grmember

and write Advanced reference qualifier as below

javascript&colon; 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.<requested_for_field_name>).getMyGroups());

// replace requested for back end name at <requested_for_field_name> 

 

Please mark my answer as Helpful, if it is correct and help you.

Thank you

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@pjftenorio 

your variable should refer to sys_user_group and not sys_user_grmember since you want to show groups

Do this in advanced ref qualifier

javascript&colon; 'sys_idNIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.requested_for).getMyGroups());

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

Hi @Ankur Bawiskar ,

I already updated with the above script but it returns all the group. Not the group of the requested for user.

pjftenorio_0-1694672000628.png

pjftenorio_1-1694672012647.png

 

 

 

@pjftenorio 

there was a type in my above response; it should be IN and not NIN

update as this

javascript&colon; 'sys_idIN' + new global.ArrayUtil().convertArray(gs.getUser().getUserByID(current.variables.requested_for).getMyGroups());

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

Hi @Ankur Bawiskar  I have simliar requirment but slight change already that group reference variable had few static groups like (Group1, Group2, Group3, Group4, Group5, Group6) if requested for is part of these 6 groups then display all or else if he is part of first 3 groups out of 6 static groups then display only those 3 groups and exclude rest of the groups How can i achieve this one ?