Before query business rules example?

ram2497
Tera Contributor

Before query  business rules example?

1 ACCEPTED SOLUTION

Priyanka136
Mega Guru

Hi ram2497,

You can use a query BRule that executes before the database query is made to prevent from accessing certain records

Write BRule on ('incident') table --- When before-query

Example Script:-

This example prevents users from accessing incident records unless they have the ITIL role are listed in the caller or Opened by field . So, for ex, when self-service users open a list of incidents, they can only see the incidents they submitted.

if(!gs.hasRole("itil")&& gs.isInteractive()){
  var u = gs.getUserID();
  var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list","CONTAINS", u);
  gs.print("query restricted to user: "+ u);}

Or You can refer the Service Now Docs as well.

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/useful_scripts/concept/c_E...

Please mark it Correct or Helpful, if it works based on impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com

View solution in original post

4 REPLIES 4

Abhijeet14
Mega Expert

Hi,

 

Refer this link

https://community.servicenow.com/community?id=community_question&sys_id=febb4f96dbf657c0200f0b55ca961937

 

 

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

 

 

Regards,

Abhijeet Bangera

www.dxsherpa.com

Hussain Kachwal
Mega Guru

Hello Ram,

Refer the below:

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/useful_scripts/concept/c_ExScptDftBfrQryBsnRu.html

https://www.servicenowguru.com/scripting/business-rules-scripting/controlling-record-access-before-query-business-rules/

 

Kindly mark as Answered or Helpful, if applicable.

-Hussain K

Ahmmed Ali
Mega Sage

Hello,

 

There is one OOTB before query BR on user table. it basically checks if logged in user is admin. if not then it will add query as active is true.

 

It is to restrict other users than admins to see inactive users.

This can be done with ACL also. but advantage of BR is that it will not show any message like, 10 records were hided because of security reasons.

 

Hope this helps you.

 

Thanks,

Ali 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Priyanka136
Mega Guru

Hi ram2497,

You can use a query BRule that executes before the database query is made to prevent from accessing certain records

Write BRule on ('incident') table --- When before-query

Example Script:-

This example prevents users from accessing incident records unless they have the ITIL role are listed in the caller or Opened by field . So, for ex, when self-service users open a list of incidents, they can only see the incidents they submitted.

if(!gs.hasRole("itil")&& gs.isInteractive()){
  var u = gs.getUserID();
  var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list","CONTAINS", u);
  gs.print("query restricted to user: "+ u);}

Or You can refer the Service Now Docs as well.

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/useful_scripts/concept/c_E...

Please mark it Correct or Helpful, if it works based on impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com