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.

Way to list only records that value of User_name filed is me.

matsui
Tera Contributor

I have some records.
Those records has User_name filed.
User_name is Reference for sys_user.

 

I want to list only records that value of User_name filed is me.
As an example:
When UserA logged in, it shows only value of User_name filed is UserA
When UserB logged in, it shows only value of User_name filed is UserB

 

I tried to find expected filter, it can't select logged in user name like gs.getUserID().
I think that I can do it using business rule of addEncodedQuery, but I don't have any idea...

 

How I create a business rule to resolve this issue.

 

Regards,

5 REPLIES 5

Bert_c1
Kilo Patron

@matsui 

 

Try the following script to include records where the desired field is empty:

 

 

 

restrictRecords();
function restrictRecords() {
	current.addEncodedQuery('assigned_toISEMPTY^ORassigned_to=javascript:gs.getUserID()');
}

 

 

replace 'assigned_to' with your field. And maybe add a Condition: !gs.hasRole('admin')  so users with the admin role can see all records.