Using getValue() to Get Assignment_group.name On sys_user_group Table

JosephW1
Tera Guru

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

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

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');
}
})();

View solution in original post

7 REPLIES 7

Harsh Vardhan
Giga Patron

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');
}
})();

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?

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();

})();

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()){}.