
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:13 AM
I am trying to return the string of the queried group with the following code, but it always returns NULL. If I change the getValue('name') to getRowCount(), then it returns 1, showing that the query itself is working but the getValue is not. As well as using 'name', I also tried group, assignment_group, and assignment_group.name, but none of them worked either. I also tried getDisplayValue('name') and getElement('name'), but those did not work.
I am using the Widget Editor, and my entries are as follows:
Server Script
(function(){
var groups = new GlideRecord('sys_user_group');
groups.addQuery('name', 'Database Atlanta');
groups.query();
data.test = groups.getValue('name');
})();
HTML Template
<div class="info">
Groups Output: {{ data.test }}
</div>
Please, what do I need to change the .getValue('name') to in order to return the string value of the group's name?
Kind Regards,
Joseph
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:21 AM
try now
(function(){
var groups = new GlideRecord('sys_user_group');
groups.addQuery('name', 'Database Atlanta');
groups.query();
if(groups.next()){
data.test = groups.getValue('name');
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:21 AM
try now
(function(){
var groups = new GlideRecord('sys_user_group');
groups.addQuery('name', 'Database Atlanta');
groups.query();
if(groups.next()){
data.test = groups.getValue('name');
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:28 AM
Thank you, that worked! That brings up a new question, though. I was trying to use while(groups.next()) earlier, but it wasn't working the way I was using it, so I tried simplifying the query to the one I posted.
I'm ultimately trying to get it to return a string of all the groups that have 'Database' as their parent.
Here is the more advanced query which still is not working.
(function(){
var grps = new Array();
var groups = new GlideAggregate('sys_user_group');
groups.addQuery('parent', 'Database');
groups.addAggregate('COUNT');
groups.groupBy('name');
groups.query();
while(groups.next()){
grps.push(groups.getValue('name').toString());
}
data.test = grps.join();
})();
What do I need to change to get that code to produce the desired joined string of group names for the query?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:33 AM
try now
(function(){
var grps = new Array();
var groups = new GlideAggregate('sys_user_group');
groups.addQuery('parent.name', 'Database');
groups.addAggregate('COUNT');
groups.groupBy('name');
groups.query();
while(groups.next()){
grps.push(groups.getValue('name'));
}
data.test = grps.join();
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 08:37 AM
Once again, your suggestion worked. Very good, I wish I had your knowledge! 🙂
Please, where can I learn why the original query that I posted in this thread did not work? I'd like to learn why it needed while(groups.next()){}.