How to create a permanent filter on custom table created in application?

vaibhavbhatnaga
ServiceNow Employee
ServiceNow Employee

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

1 ACCEPTED SOLUTION

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.


View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

Hi Vaibhav,



Take a look at reference qualifiers. It filters the list of available items to a reference field.




Reference Qualifiers - ServiceNow Wiki


Hi Chuck,



Thanks for your response.



Reference is used to get the data from other table. My problem is, suppose I have below records in table platform



Employee     Manager


A                                       M1


B                                       M1


C                                       M3



If I open my application and click on Platform table, it shows me all 3 records. But if gs.getUser().getFullName() = M1 then i want it should show 2 records only.



Thanks


I think I understand. You want to get all the records where the person at the keyboard is the manager.



Is the Manager field a reference field to sys_user?



If so, then your (simple) reference qualifier would look more like this:



Manager | is (dynamic) | Me



That's it. No script. Just show me the records where I am the manager so I can pick employees A and B.


You want to say that your manager field is dependent on employe field or employee field on manager field.



it can be done using dependent value in dictionary of the field.



And you need to add proper code in advance reference qualifier.



try this,



i will try to give you exact code line