How to create the advance user criteria ?

ads
Tera Expert

Hi All, 

I want to create an user criteria if the user location is one of location1,location2,location3 and the company is not company1, I have tried with the below user criteria script, but Its not working,

 

Country('location1,location2,location3');

function Country(country) {
var retVal;
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
if ((country.indexOf(usr.location) > -1) && usr.company != 'c3fdaf724782c1102950c261e36d4373') {
retVal = true;
} else {
retVal = false;
}
return retVal;

}

 

Can anyone help me on this.

 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ads 

use this

1) it's recommended to use user_id instead of gs.getUserID() in user criteria script

answer = checkCondition();

function checkCondition(country) {
	var usr = new GlideRecord('sys_user');
	usr.addQuery('sys_id',user_id);
	usr.addQuery('location.name', 'IN', 'location1,location2,location3');
	usr.addQuery('company.name', '!=', 'company1');
	usr.query();
	return usr.hasNext();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

8 REPLIES 8

@Ankur Bawiskar  - Hi, After testing with some users, its not working for the location1, can you please check once.

ads
Tera Expert

Hi @Ankur Bawiskar - The script is not working for the location. Can you please have a look.

 

Thanks

Suraj Tiwari
Tera Contributor

@Ankur Bawiskar is user_id containing the logged-in user sysid? if yes then how?

 

@Suraj Tiwari 

yes user_id contains logged in user sysId.

it's defined at platform level

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