- 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 03:17 AM
Thank you for the clarification. Try this for your script include instead. It returns a comma separated list of group names. This code is untested.
var returnRole = Class.create();
returnRole.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRole: function(){
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 03:50 AM
Hi Chuck,
Its not working .
I tried to push the values into the array in another way:
arr.push(grGroup.getValue('group'));
But thats again throwing the same org.mozilla.NativeArray error.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 03:52 AM
Hi Shipra,
Debugging scripts via the community is always a good challenge. Can you provide some details of what it is doing (or not doing)? You've got some debug statements in there (alert, gs.log()), etc. How far is it getting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 04:04 AM
That's very odd because I'm not returning an array. I'm returning a comma separate string of names. Let me do a little checking...