Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

User criteria addEncodedQuery

Bradley
Tera Contributor

Good Morning,

I'm writing a script for the user criteria to check if the company = a specific sys ID and grade is either two sys IDs

 

 

var userGR = new GlideRecord('sys_user');  // Create a new GlideRecord object for the sys_user table
userGR.get(user_id);
var encoded = gr.addEncodedQuery('company=e1c9d9a31b15d4d09732dd39cd4bcbbe^u_grade=122a41e01b2998947ca8620e6e4bcb62^ORu_grade=d22a41e01b2998947ca8620e6e4bcb62^ORu_grade=5a2a41e01b2998947ca8620e6e4bcb62^ORu_grade=1e2a41e01b2998947ca8620e6e4bcb62');  // Filter to only show users with the grade 6/SCS and in the company HMRC
if (userGR == encoded)
    answer = true;
else
    answer = false;
Currently not working. Is their a better way to write and get it working?
1 ACCEPTED SOLUTION

@Bradley 

the working code I already shared, did you check that?

var userGR = new GlideRecord('sys_user'); // Create a new GlideRecord object for the sys_user table
userGR.addQuery('sys_id', user_id);
userGR.addEncodedQuery('company=e1c9d9a31b15d4d09732dd39cd4bcbbe^u_grade=122a41e01b2998947ca8620e6e4bcb62^ORu_grade=d22a41e01b2998947ca8620e6e4bcb62^ORu_grade=5a2a41e01b2998947ca8620e6e4bcb62^ORu_grade=1e2a41e01b2998947ca8620e6e4bcb62'); // Filter to only show users with the grade 6/SCS and in the company HMRC
userGR.query();
answer = userGR.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

6 REPLIES 6

@Bradley 

the working code I already shared, did you check that?

var userGR = new GlideRecord('sys_user'); // Create a new GlideRecord object for the sys_user table
userGR.addQuery('sys_id', user_id);
userGR.addEncodedQuery('company=e1c9d9a31b15d4d09732dd39cd4bcbbe^u_grade=122a41e01b2998947ca8620e6e4bcb62^ORu_grade=d22a41e01b2998947ca8620e6e4bcb62^ORu_grade=5a2a41e01b2998947ca8620e6e4bcb62^ORu_grade=1e2a41e01b2998947ca8620e6e4bcb62'); // Filter to only show users with the grade 6/SCS and in the company HMRC
userGR.query();
answer = userGR.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

Ankur Bawiskar
Tera Patron
Tera Patron

@Bradley 

your script is wrong

use this

var userGR = new GlideRecord('sys_user'); // Create a new GlideRecord object for the sys_user table
userGR.addQuery('sys_id', user_id);
userGR.addEncodedQuery('company=e1c9d9a31b15d4d09732dd39cd4bcbbe^u_grade=122a41e01b2998947ca8620e6e4bcb62^ORu_grade=d22a41e01b2998947ca8620e6e4bcb62^ORu_grade=5a2a41e01b2998947ca8620e6e4bcb62^ORu_grade=1e2a41e01b2998947ca8620e6e4bcb62'); // Filter to only show users with the grade 6/SCS and in the company HMRC
userGR.query();
answer = userGR.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