Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

gs.getUser().isMember is not working in script include

GANESH23
Tera Contributor

Hi Folks,

Good Morning...

i have created one script include, which is using in advanced reference qualifier. i am check gs.getUser().isMember in script include but it is not working. please find my script below.

var filterUsersList = Class.create();
filterUsersList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
filterUser: function() {
var grpList = '';
var custAccount = current.u_account;
if (gs.getUserID().isMemberOf('n') || gs.getUserID().hasRole('admin')) {
if (custAccount != '') {
gs.info("Logged in user"+gs.getUserID());
var users = new GlideRecord('sys_user');
var qc = users.addQuery('company', custAccount);
qc.addOrCondition('company', '54cffe00db66fb4092b6c9fb0b9619a3');
users.query();
while (users.next()) {
grpList += (',' + users.sys_id);

}
}
return 'sys_idIN' + grpList;
}

 

this script is i have check with client callable.

 

Thanks,

Mohan.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

update as below

You had issue with the method; you were using incorrect one

gs.getUser().isMemberOf(Group Name') -> correct syntax

var filterUsersList = Class.create();
filterUsersList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
filterUser: function() {
var grpList = '';
var custAccount = current.u_account;
if (gs.getUser().isMemberOf('n') || gs.hasRole('admin')) {
if (custAccount != '') {
gs.info("Logged in user"+gs.getUserID());
var users = new GlideRecord('sys_user');
var qc = users.addQuery('company', custAccount);
qc.addOrCondition('company', '54cffe00db66fb4092b6c9fb0b9619a3');
users.query();
while (users.next()) {
grpList += (',' + users.sys_id);

}
}
return 'sys_idIN' + grpList;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Hi,

for getting logged in user sys_id -> gs.getUserID();

gs.getUser() will give you the object of User record

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

GANESH23
Tera Contributor

Hi,

Got it.

i only did small mistake in script. glide record var name given wrong while quering.

Thanks

Glad to know.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader