User Creteria not working for a Record Producer

SandeshD
Tera Contributor

Hi Team , 

 

We have a Record Producer created , we have a custom column/field called as "Function" whose value is "People" in the User table , we want to hide the Record Producer from these People function user.

 

I have tried the below script in the Not available for , 

 

answer = true;
var grp = new GlideRecord('sys_user');
grp.addQuery('sys_id', user_id);
grp.addEncodedQuery('u_sf_function=******');//sf function=people
grp.query();
if (grp.next()) {
    answer = false;
}

Which is failing , still the users are able to see it , kindly assist!
8 REPLIES 8

Shivalika
Mega Sage

Hello @SandeshD 

 

You have just used user_id

 

Either use gs.getUserID() or gs.getUser() and dot walk to user id. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Anoja
Mega Sage

Hi,

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('add your query');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next())
    answer = false;
else
    answer = true;

SandeshD
Tera Contributor

Not Working.

Ankur Bawiskar
Tera Patron
Tera Patron

@SandeshD 

so please add this script in User Criteria and add in Available For related list

I hope you are using the correct field name and the correct value to compare for u_sf_function

var grp = new GlideRecord('sys_user');
grp.addQuery('sys_id', user_id);
grp.addEncodedQuery('u_sf_function=******'); //sf function=people
grp.query();
answer = !grp.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