User Criteria for Catalog item not working

Omkar Jori
Tera Expert
Hi All,
I have a custom field named Responsible branch office in User table.
I only want to show the catalogs related with that branch to the user.

I used below user criteria script but its not working.
answer = checkCondition();

function checkCondition(country) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',user_id);
user.addEncodedQuery("u_responsible_branch_office=42393ff3835132107f59e530ceaad3fb");
user.query();
return user.hasNext();
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Omkar Jori 

is that custom field a reference one?

try to use setWorkflow(false) during query

answer = checkCondition();

function checkCondition(country) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',user_id);
user.addEncodedQuery("u_responsible_branch_office=42393ff3835132107f59e530ceaad3fb");
user.setWorkflow(false);
user.query();
return user.hasNext();
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

4 REPLIES 4

palanikumar
Giga Sage
Giga Sage

Is the responsible branch always same?

I don't see any issue in this.

You can try removing the country attribute in function declaration

 

Thank you,
Palani

Ankur Bawiskar
Tera Patron
Tera Patron

@Omkar Jori 

is that custom field a reference one?

try to use setWorkflow(false) during query

answer = checkCondition();

function checkCondition(country) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',user_id);
user.addEncodedQuery("u_responsible_branch_office=42393ff3835132107f59e530ceaad3fb");
user.setWorkflow(false);
user.query();
return user.hasNext();
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi @Ankur Bawiskar 
Thanks for the input, it works but Not working for admins ?, Can you suggest anything here? 

@Omkar Jori 

Glad to know that it worked for non-admins.

Why are you worried for admins?

Admins are not going to raise request in Production

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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