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.

Get display name of group field printed on alert

manasa0590
Tera Contributor

hey,

 

I have a field on the form " assignment group" referring to group table. I want to check whether the logged in user is member of any groups and print the group names as an alert message . Currently I get sys_ids of the groups when i print. But i want the group names printed. Please let me know what I should code to get the names instead of sys_ids.

 

Thanks

Manasa

2 ACCEPTED SOLUTIONS

Omkar Ranjane
Tera Guru

Hi @manasa0590 ,

 

If you are using Glide Record, then just use getDisplayValue()

The below code snippet is just for example.

var current = new GlideRecord('sys_user_grmember');
current.addQuery('user', '<login user sys_id>');
current.query();
var userGrp = ""; // store names in string
var userGrp1 = []; // store names is array
while(current.next()){
    userGrp += current.group.getDisplayValue() + ",";
    userGrp1.push(current.group.getDisplayValue());
}
gs.info("Group names in string = " + userGrp);
gs.info("Group names in array = " + userGrp1)

Output will be something like 

OmkarRanjane_0-1674198007814.png

 

If your question is solved, please close the topic by marking my answer "Accept as Solution". This will help others searching for a similar question and will remove the topic from the unsolved list.

View solution in original post

@manasa0590 

getDisplayValue() won't work in client side glide record

you can dot walk to name field and push that into array

userGrp += gr.group.name + ',';

userGrp1.push(gr.group.name.toString());

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

10 REPLIES 10

@manasa0590 

I could see you marked response as correct.

But your question was about getting display value in client side which I shared above

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

this is in continuation to the requirement. Should i need to raise a fresh question as this is marked answered already?

Thank you Ankur. 

I need one more help. We have group names in the below formats.

1. India-BDC10-Duty manager

2. India-CHE09- Duty engineer

4. India-HYD12- Duty manager ....

Group names with prefix "India-".

 

I will get group names as return from script include to client script

From the list of group names (user is a member of) , I want to fetch the BDC10,CHE09,HYD12 only. i.e anything after the first hyphen and before the second hyphen.

 

and then set those values as choices(drop down) for a field on the form. How to do this. Please help.

 

Thank you,

Manasa

 

Hi Omkar,

 

 I created the script include and added this logic in there , it worked. Thank you.

 

Thanks,

Manasa

Mohith Devatte
Tera Sage
Tera Sage

Hello @manasa0590 where ever you are printing the value in the alert or where you are trying to access the value of the group name just put .getDisplayValue();

like gr.group.getDisplayValue();

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks