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

Community Alums
Not applicable

Hi @manasa0590 ,

can you please share the code what are you trying, is req is a GlideRecord object, if yes can we try something like this example :

 

g_form.setValue('partitions', req.getDisplayValue(u_my_partitions));

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.

Hi Omkar,

I am trying to print this on the client side using alert.

manasa0590_0-1674215228141.png

it doesnt work. Let me know what is the mistake.

 

Thank you

Manasa

@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