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.

How to create user criteria based on Title

jituksingh
Kilo Guru

Hi,

I need to create user criteria based on Title. I used below script and it work fine for one Title however I have to use multiple Title and when I use multiple Title it doesn't work.

var userCheck = new GlideRecord("sys_user");

userCheck.addQuery("sys_id", gs.getUserID());

userCheck.query();

if (userCheck.next()) {

if (userCheck.title.indexOf('Customer Service Supervisor'||'Triage Supervisor')>-1)
answer = true;
else
answer = false;

}

 

Regards,

Jitendra Singh

1 ACCEPTED SOLUTION

Matthew Smith
Kilo Sage

Hi Jitendra

Try this which seems to work for me (remember to clear browser session after updating the User Criteria):

checkCondition();

function checkCondition() {

	var titles = ['Customer Service Supervisor','Triage Supervisor'];
	var title = gs.getUser().getRecord().getValue('title');

	for (var i=0; i < titles.length; i++){  

		if (title.toLowerCase() == titles[i].toLowerCase()) {
			return true;
		}
	}

	return false;
}

- Matt

View solution in original post

5 REPLIES 5

Matthew Smith
Kilo Sage

Hi Jitendra

Try this which seems to work for me (remember to clear browser session after updating the User Criteria):

checkCondition();

function checkCondition() {

	var titles = ['Customer Service Supervisor','Triage Supervisor'];
	var title = gs.getUser().getRecord().getValue('title');

	for (var i=0; i < titles.length; i++){  

		if (title.toLowerCase() == titles[i].toLowerCase()) {
			return true;
		}
	}

	return false;
}

- Matt

Hi Matt,

Its working for only one Title "Customer Service Supervisor".

 

Regards,

Jitendra Singh

I re-tested in my instance and it works fine for me.

Can you check there are no extra spaces in the "Triage Supervisor" User title, that the code is re-copied as I edited it once after posting, and when impersonating users ensure you try in a new incognito window. 

- Matt

My bad. It worked. Thanks a lot!