- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 12:59 PM
I am struggling to get list of group names based on group type. The "type" column have List type field in sys_user_group table. Type columns can have more than 1 value (Incident, problem, approver, security, etc). I created a script using GlideRecord to print list of group names but it returning empty and I am wondering why.
user variable is a sys_id of Type from sys_user_group_type table. I was able to get string value in groupType variable. Now I added another GlideRecord to use groupType variable to get list of group names based on type however I am getting a empty result. Was that has to do with List type field in type column? I was able to test in different query to see if it able to print results in list and it worked but not with getGroup.addQuery('type', 'CONTAINS', groupType);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:53 AM
Try this and let me know the results. I have added few debugging statements. Please check the system log after running this.
I thought you are sending the user in the user field. Lets see by printing these variables.
else if(option == "grouptype"){
var groupType = '';
var managerName = '';
var list = '';
var groupName = '';
gs.log('+++++++++++++user is '+user);
var getType = new GlideRecord('sys_user_group_type');
getType.addQuery('sys_id', user);
getType.query();
while(getType.next()){
groupType = getType.sys_id+'';
gs.log('++++++++++++++++my group type sys id is ---'+groupType);
var getGroup = new GlideRecord('sys_user_group');
getGroup.addQuery('type', 'CONTAINS', groupType);
getGroup.query();
while(getGroup.next()){
list += getGroup.name + ';\n';
}
gs.log('++++++++++++++++my list is ---'+list);
}
managerEmail = "test";
return list;
managerEmail;
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:53 AM
Try this and let me know the results. I have added few debugging statements. Please check the system log after running this.
I thought you are sending the user in the user field. Lets see by printing these variables.
else if(option == "grouptype"){
var groupType = '';
var managerName = '';
var list = '';
var groupName = '';
gs.log('+++++++++++++user is '+user);
var getType = new GlideRecord('sys_user_group_type');
getType.addQuery('sys_id', user);
getType.query();
while(getType.next()){
groupType = getType.sys_id+'';
gs.log('++++++++++++++++my group type sys id is ---'+groupType);
var getGroup = new GlideRecord('sys_user_group');
getGroup.addQuery('type', 'CONTAINS', groupType);
getGroup.query();
while(getGroup.next()){
list += getGroup.name + ';\n';
}
gs.log('++++++++++++++++my list is ---'+list);
}
managerEmail = "test";
return list;
managerEmail;
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 01:18 PM
I modified to your example and got script error result, "The reference to entity "E" must end with the ';' delimiter.".
but in system logs, it show 3 log information which are correct. Here a screenshot,
I wonder why the system logs have correct values but got script error in UI Pages.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 01:25 PM
That seems to me an HTML error. You have a error in your HTML.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 01:34 PM
That is strange. The list variable is put in html textbox like this <td><textarea id="holdtext" rows="1000" cols="100">${list}</textarea></td> where I put list of results there.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 01:39 PM
There is something else in your script which is failing. Not the line you mentioned. Remove that line and see if you still see the error
Please mark this response as correct or helpful if it assisted you with your question.