We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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
Mega 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

As of today, above method is not suggested. 

You need to use user_id instead of gs.getUser() method, as it can create cache conflicts.

 

See KB0780775 for reference: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0780775

 

Regards,

Simone