Help with Script Include and Advanced Reference qual

Cameron Wilson
Tera Expert

I am working in a custom scoped application and have some fields I have added that reference the User table. I am trying to limit the users available in the fields to a few groups those users would be apart of and being that this is a scoped application I am unable to use the global reference qualifiers.

I have a script include I am working on but something is not right as the field still just pulls all users.

the reference qual on the field is - javascript: active=true^getOHMMembers();

my script include is as follows and is created in the custom application's scope.

 

var getOHMMembers = Class.create();
getOHMMembers.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getMember : function(){
var grpName = 'APP_SN-CAD-OHMConfig';
var user_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group', grpName);
getMembers.query();

while(getMembers.next()){
user_array.push(getMembers.user + '');
}

return 'sys_idIN' + user_array.toSring();

},

type: 'getOHMMembers'
});

I am trying to get just one groups members to pull back but I will have a few groups that will be added once I can get this working. I have also tried to use group.name in the query as well as the sys_id of the group in the variable but all results are the same. 

Any help is much appreciated!

1 ACCEPTED SOLUTION

RAHUL YADAV9
Mega Guru

In advance ref qualifier use

javascript: 'sys_idIN' + new GetGpMember().getUsers();

Script include:

var GetGpMember = Class.create(); GetGpMember.prototype = {

initialize: function(){ },

getUsers: function()

{

var array = [];

var gr = new GlideRecord("sys_user_grmember");

gr.addQuery("group.name", "Your group name");

gr.query();

while(gr.next())

{

array.push(gr.getValue('user'));

}

return array.toString();

},

type: 'GetGpMember'

};

 

Feel free to mark correct and helpful.

View solution in original post

4 REPLIES 4

RAHUL YADAV9
Mega Guru

In advance ref qualifier use

javascript: 'sys_idIN' + new GetGpMember().getUsers();

Script include:

var GetGpMember = Class.create(); GetGpMember.prototype = {

initialize: function(){ },

getUsers: function()

{

var array = [];

var gr = new GlideRecord("sys_user_grmember");

gr.addQuery("group.name", "Your group name");

gr.query();

while(gr.next())

{

array.push(gr.getValue('user'));

}

return array.toString();

},

type: 'GetGpMember'

};

 

Feel free to mark correct and helpful.

Thank you so much Rahul! That worked like a charm.

 

If I wanted to add another group so that I am looking at two groups of members, is that possible?

You can add one more gr.addQuery and pass another group name. But make sure before pushing the user to array validate if that user is already part of that array or not.

Thank you Rahul!