- 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-20-2023 05:15 AM
I could see you marked response as correct.
But your question was about getting display value in client side which I shared above
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-20-2023 05:47 AM
this is in continuation to the requirement. Should i need to raise a fresh question as this is marked answered already?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 05:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 05:08 AM
Hi Omkar,
I created the script include and added this logic in there , it worked. Thank you.
Thanks,
Manasa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 11:04 PM
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