How to create a user criteria with advance script ?

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,

 

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();
}

 Can anyone help me on this ? 

7 REPLIES 7

t_sadahisa
Giga Guru

Hello,

 

I think there is no mistake in your code.

(As you know, user_id is recommend instead of "gs.getUserID()" in user criteria advanced scripts)

So, You should check other points. (maybe...company or location name?)

 

Thanks,

Hi @t_sadahisa  - The company & locations name are correct, still Its not working. Do we have any other aspects as Its not working.

Do you use user criteria in service portal ?

Please check following points.

 

1. Do you set system properties?

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/task/activate-...

 

2. Do not make similar settings same as Usercriteria at the same time (example: role, etc.).

I heard user criteria is not working in the situation from collegue.

 

I'll hope my comment help you.