Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need find user's with role (itil) via script

Pastupe
Mega Guru

Hello,
I cannot find here how to get list of user's from database which have ITIL role.

I have seen element g_user.hasRole , but this work only on Client side.
I need find way how to build script with GlideRecord to be able query sys_user table via Script Background

I have my script below.
Can someone experienced in script's help please.
I tried several examples with gs...... but nothing work and I cannot find how to include query in C variable that user have itil role.
I tried add query in below script as------- c.hasRole('itil'); -------c.addQuery('sys_user','hasRole','itil');

I very appreciate whichever help and advice
Thank you
Petr



var c = new GlideRecord('sys_user');
c.addQuery('first_name','CONTAINS','Pe');
c.orderBy('fist_name');
c.query();
while (c.next()) {
gs.print(c.email)
}

6 REPLIES 6

Thanks ravi1.tandon . Its an awesome filter condition you provided.


Silly question but could someone provide on opposite query operator if I wanted to find users that do not have the itil role?