- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 10:03 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 11:00 PM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 04:01 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 10:16 PM
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 11:00 PM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 03:47 AM
Hi Omkar,
I am trying to print this on the client side using alert.
it doesnt work. Let me know what is the mistake.
Thank you
Manasa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 04:01 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader