How to get result using query from List field type through GlideRecord?

bbf3562
Kilo Guru

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.

find_real_file.png

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

1 ACCEPTED SOLUTION

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.

View solution in original post

15 REPLIES 15

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.

I modified to your example and got script error result, "The reference to entity "E" must end with the ';' delimiter.".


find_real_file.png



but in system logs, it show 3 log information which are correct. Here a screenshot,



find_real_file.png


find_real_file.png


I wonder why the system logs have correct values but got script error in UI Pages.


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.

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.


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.