User Criteria Not working

hiteshpradh
Tera Contributor

Hello Everyone I had a task to create an user criteria for the following condition I have made it and was testing for users and its not working properly as it should can anyone help with this?
Its kind of urgent.
the provided criteria is in the photo

Screenshot 2026-06-12 090411 (3).png

 my query is 

var id = gs.getUserID();

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', id);

 

gr.addEncodedQuery(

    'departmentINjavascript:new Department().recursive_search_byID("53963")' +

    '^ORdepartmentINjavascript:new Department().recursive_search_byID("53956")' +

    '^OR(departmentINjavascript:new Department().recursive_search_byID("55375")^u_reporting_entity.u_codeIN3,936)' +

    '^OR(departmentINjavascript:new Department().recursive_search_byID("65528")^u_reporting_entity.u_codeIN3,936)' +

    '^OR(departmentINjavascript:new Department().recursive_search_byID("80009421")^u_reporting_entity.u_codeIN3,936)'

);

gr.query();

if (gr.next())

    answer=true;

else

    answer=false;

5 REPLIES 5

Mark Manders
Giga Patron

Did you check the user criteria diagnostics?

 

I am not sure what it is you are trying to do, but your and/or conditions seem to be weird, since you are using the same ones a couple of times as 'and'.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

I have been asked for a user criteria and the condition is in the picture provided., and the script is the which I wrote.

That doesn't sound like a valid ask. You can't simply copy this one on one. Tell them you can only create something if you understand what it is you are creating, because it doesn't sound like you do. 
And again my question: did you check the user criteria diagnostics.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Tanushree Maiti
Tera Patron

Hi @hiteshpradh 

 

Is this AddedEncodedQuery is working in filter  of Native view? Are you getting result?

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti