---
sourceDocument: Australia API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/api-reference

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Restricting record access

# Restricting record access {#ariaid-title1}

Release version: Australia  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Restricting record access

This content explains how to restrict user access to specific records in ServiceNow by using query business rules that execute before a database query.
It highlights a practical example of limiting access to incident records based on user roles and associations with the record.
Additionally, it provides scripts for scheduling business rules on weekdays, setting date fields dynamically based on the day of the week, and validating date/time input formats.
Show full answer Show less  

## Key Features

* **Query Business Rule for Access Restriction:** You can create a business rule that runs before a query to filter records users can see. For example, restricting incident records so only users with the `itil` role or those listed as Caller, Opened by, or on the Watch list can access them.
* **Example Script for Incident Access Restriction:** The provided script checks user role and filters incident records accordingly, ensuring self-service users only see incidents they submitted.
* **Scheduling Scripts for Weekdays:** A sample script template is provided to run scripts only on weekdays, excluding weekends.
* **Dynamic Date Field Setting:** A function example sets a date field to either the current week's Monday or the next Monday based on the current day, useful for scheduling or planning workflows.
* **Date/Time Validation Script:** Guidance on creating a validation script to ensure date/time fields accept only properly formatted input, with built-in format checking aligned with the instance's date/time format.

## Key Outcomes

* **Controlled Record Visibility:** By implementing query business rules, you can enforce fine-grained access control at the query level, improving data security and user experience.
* **Flexible Scheduling and Automation:** Using weekday scheduling and dynamic date setting scripts helps automate business processes that depend on specific timing or calendar logic.
* **Improved Data Quality:** Validating date/time input prevents user errors and ensures consistency in date-related data fields.
* **Customization Caution:** The access restriction method described is a customization not supported by Now Support and must be thoroughly tested before deployment.  
You can use a query business rule that executes before the database query to prevent users from accessing certain records.  
Warning:  
The customization described here was developed for use in specific instances, and is not supported by Now Support. This method is provided as-is and should be tested thoroughly before implementation. Post all questions and comments regarding this customization to our community [forum](http://community.service-now.com/).

Consider the following example from a default business rule that limits access to incident
records.  
{#c_ExScptDftBfrQryBsnRu__table_jfv_wym_jq__entry__3}

| Name | Table | When |
|-|-|-|
| incident query | Incident | before, query |
[Table 1. Default business rule limits access to incident records]

{#c_ExScptDftBfrQryBsnRu__table_jfv_wym_jq}  

## Restricting record access {#c_ExScptDftBfrQryBsnRu__example_xcz_wnh_q2c}

In the following example, users are restricted from accessing incident records unless they have the itil role and are listed in the Caller or Opened by field. 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);}

Note:  
You can also use access controls to restrict the records that users can see. For information, see [Access Control Lists (ACLs)](https://www.servicenow.com/docs/access?context=access-control-rules&version=australia&pubname=australia-platform-security&ft:locale=en-US).

## Schedule script for weekdays {#c_ExScptDftBfrQryBsnRu__section_nv5_rnh_q2c}

Type: Business Rules/Client Scripts.  
This script schedules the script for weekdays. Insert any script where it says "Your Script Here."

    var go ='false';
    var now =new Date(); 
     
    // Correct time zone, which is by default GMT -7 
    now.setHours(now.getHours()+8);
    var day = now.getDay(); 
     
    // No go on Saturday or Sunday 
    if(day !=0&& day !=6){
     
    // (your script here)
     
    }

## Set date field according to current date {#c_ExScptDftBfrQryBsnRu__section_orj_vnh_q2c}

This script sets a date field depending on the current day of the week. In this example, if the day is Monday through Wednesday, it sets the date to this coming Monday; otherwise it sets the date field to next Monday.

    function setCabDate(){
    var today = new Date();
    var thisDay = today.getDay();

    //returns 0 for Sunday, 1 for Monday, through 6 for Saturday.
    var thisMon = new GlideDateTime();
    thisMon.setDisplayValue(gs.beginningOfThisWeek());
    var nextMon = thisMon.getNumericValue();
    nextMon +=(1000*60*60*24*7);
     
    if((thisDay <4)&&(thisDay >0))
      //if today is Mon thru Wed (thisDay = 1, 2, or 3), set cab to this coming Monday.
      current.u_req_cab_rev_date.setDateNumericValue(thisMon.getNumericValue());
    else if((thisDay >=4)||(thisDay ==0))
      //if today is Thurs thru Sun (thisDay = 4, 5, 6, or 0), set cab to next Monday.
      current.u_req_cab_rev_date.setDateNumericValue(nextMon);
    }

To validate the input of all date/time fields, you can use the following in a validation script (System DefinitionValidation Scripts). Because the date/time format is hard coded in this script, it must match your instance's date/time format. If your instance's date/time format changes, you must update your validation script.  
Set the validation script's type to Date/Time. Then, with this validation script, if a user enters an incorrect format in a date/time field, they receive an error message.

    function validate(value){
    // empty fields are still valid dates 
    if(!value) 
        return true; 
     
    // We "should" have the global date format defined always defined. But there's always that edge case. 
    if(typeof g_user_date_time_format !=='undefined')
        return isDate(value, g_user_date_time_format); 
     
    // if we don't have that defined, we can always try guessing 
    return parseDate(value)!==null;}

For more information, see [Validation script use case - Date and time](https://servicenow-prod.fluidtopics.net/WoMBcAO8F69wuUTGxcRSPg "To validate the input of all date/time fields, you can use the following in a validation script ( System Definition > Validation Scripts ).").

*[\>]: and then


