- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2016 04:18 AM
Hello,
I am new to ServiceNow platform. Please take this question accordingly.
I created a custom table in my application. Along with other fields I have Employee and Manager fields also. While showing the records I want that only those employee data is visible where manager is javascript:gs.getUser().getFullName(). How I can create this filter? I want this filter by default. It's not that every time I create a filter
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2016 11:37 AM
Hi Vaibhav,
Perhaps what you are looking for is a before query business rule. They allow you to force extra conditions that must be met anytime a record or list of records is pulled up in a form or list view. For example, the following before query business rule script on the sys_user table will limit access to user records where the manager field is set to the user that is currently logged in.
If the current user is in the "itil" group, they will not be affected by this business rule.
if (!gs.hasRole("itil")) {
var u = gs.getUserID();
var qc = current.addQuery("manager", u);
gs.print("query restricted to users who have a manger of : " + u);
}
I took this example from the following wiki article.
Scripting in Business Rules - ServiceNow Wiki
Hope this helps!
-Jose
Please mark this as helpful if appropriate.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2016 05:48 AM
If i got you right,
then you have one reference field which depends on second reference field.
I.e. Manager depends on employee rite?
if yes then let me know.....
if yes, then follow below link
http://wiki.servicenow.com/index.php?title=Adding_Dependent_Reference_Variables#gsc.tab=0
This is related to Catalog item just for your reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2016 02:13 AM
I think I am not able to explain it well. Sorry for it. Above it is the screenshot of my table and below is the records I am seeing in application.
See I am login as "Joe Administrator" but I am still seeing record for other manager also "Allen". My requirement is, it should show me 2 records only. I am looking how to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2016 11:37 AM
Hi Vaibhav,
Perhaps what you are looking for is a before query business rule. They allow you to force extra conditions that must be met anytime a record or list of records is pulled up in a form or list view. For example, the following before query business rule script on the sys_user table will limit access to user records where the manager field is set to the user that is currently logged in.
If the current user is in the "itil" group, they will not be affected by this business rule.
if (!gs.hasRole("itil")) {
var u = gs.getUserID();
var qc = current.addQuery("manager", u);
gs.print("query restricted to users who have a manger of : " + u);
}
I took this example from the following wiki article.
Scripting in Business Rules - ServiceNow Wiki
Hope this helps!
-Jose
Please mark this as helpful if appropriate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2016 03:15 AM
Thanks Jose. It worked.