- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 02:40 AM
Hi All,
i have a client script which passes role to script include in order to get all the group names of the selected role from sys_group_has_role. In sys_group_has_role, the role field is again reference to another table i.e., sys_user_group.
Kindly suggest.
Thanks!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:45 AM
Thank you. I think I understand the issue now. Per your original requirements, you wanted to pass it a role and get back a list of groups that use that role. You are passing it the sys_id of the sys_group_has_role record, not the role itself.
Change the dictionary entry on that field to reference Role (sys_user_role) and use the following scripts and you will have better luck.
/******* script include *********/
var returnRole = Class.create();
returnRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRole: function(){
gs.log('>>>DEBUG: returnRole() started...');
var list = [];
var rol = this.getParameter('sysparm_role');
gs.log(rol,'shipra0');
var grGroup = new GlideRecord('sys_group_has_role');
grGroup.addQuery('role', rol);
grGroup.query();
while (grGroup.next()) {
list.push(grGroup.group.getDisplayValue());
}
return list.join(',');
},
type: 'returnRole'
});
/******** client script *********/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var rol=g_form.getValue('u_user_role');
alert('Calling getRole... ' + rol);
var ga = new GlideAjax('returnRole');
ga.addParam('sysparm_name','getRole');
ga.addParam('sysparm_role',rol);
ga.getXML(AsyncCall);
}
function AsyncCall(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:10 AM
On using your code its returning nothing.
I did a minor change to see if it works but thats throwing the error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:16 AM
What type of field is "User role", string or reference? if it's a reference field, what table is it referencing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:21 AM
Its a reference field. Referencing to sys_group_has_role.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:45 AM
Thank you. I think I understand the issue now. Per your original requirements, you wanted to pass it a role and get back a list of groups that use that role. You are passing it the sys_id of the sys_group_has_role record, not the role itself.
Change the dictionary entry on that field to reference Role (sys_user_role) and use the following scripts and you will have better luck.
/******* script include *********/
var returnRole = Class.create();
returnRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRole: function(){
gs.log('>>>DEBUG: returnRole() started...');
var list = [];
var rol = this.getParameter('sysparm_role');
gs.log(rol,'shipra0');
var grGroup = new GlideRecord('sys_group_has_role');
grGroup.addQuery('role', rol);
grGroup.query();
while (grGroup.next()) {
list.push(grGroup.group.getDisplayValue());
}
return list.join(',');
},
type: 'returnRole'
});
/******** client script *********/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var rol=g_form.getValue('u_user_role');
alert('Calling getRole... ' + rol);
var ga = new GlideAjax('returnRole');
ga.addParam('sysparm_name','getRole');
ga.addParam('sysparm_role',rol);
ga.getXML(AsyncCall);
}
function AsyncCall(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2021 05:03 AM
HI
Could you please clarify my doubt, if possible.
In the similar requirement, I have created one custom table ABC having one the field role_name (Reference to sys_user_role table) and i have another custom table XYZ in this XYZ table we have few fields called Role(Reference to ABC table), Group_List,
Here my doubt is : How can we get the list of groups in XYZ table based on selection of Role Field ??
The Role Field is reference to ABC table.