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

Rahul RJ
Giga Sage
Giga Sage

@ads can you try below code

answer=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;

}

 

Regards,

RJ

Hi @Rahul RJ  - I tried with the script provided by you, But Its not working. Can you please check once again.

 

Thanks

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

Thanks @Ankur Bawiskar  - The above script worked.