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

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.


Screen Shot 2016-08-06 at 2.35.01 PM.png



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.




Screen Shot 2016-08-06 at 2.36.19 PM.png



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.


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.


Thanks Jose. It worked.