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

Ankur Bawiskar
Tera Patron
Tera Patron

@manasa0590 

unless you share what script you are using we cannot help

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