Working with System Properties

//Working with System Properties

Working with System Properties

Much of the behavior of a ServiceNow instance is controlled by System Properties. System properties are a great way to add options to your system and keep people (including yourself) from having to make modifications to back-end code later on. Business rules, UI actions, and UI pages rely pretty heavily on system properties just for this purpose. If I’ve ever got variable values that should be available system-wide then my first thought is to put that value in a system property that can be changed in the UI and be referenced from multiple places in the future. Chances are you’ve worked with these properties as part of your system setup. It’s always a good idea to be aware of the different properties in the system and what they do. The ServiceNow wiki contains a listing of system properties with their descriptions that you can review.
The purpose of this post is to show the different ways you can access, display, and work with properties in the system UI and in the ServiceNow scripting environment.


Creating or Editing a Property

Most of the system properties can be found in your left navigation under the ‘System Properties’ application as shown above. ALL of the properties in the system are stored in the ‘sys_properties’ table and can be viewed and edited there by typing ‘sys_properties.list’ into the left navigation filter.
You can add a property to your system simply by creating a new record in the ‘sys_properties’ table as shown in the wiki.

Adding your property to a properties page

It’s great to be able to modify properties from the properties table, but it’s a lot more convenient to make the edit through a properties page. Properties pages are what you get when you click on a module under the ‘System Properties’ application in the left navigation of your ServiceNow instance.
Properties pages are really just a URL that pulls together one or more System Property Categories into a single UI page to be viewed. You can create or modify these categories by navigating to ‘System Properties->Categories’. Here’s what one of the properties categories looks like for the Email settings out-of-box…

As you can see, there’s really not a whole lot to it. Simply give the category a name (which will be referenced in your page URL), a title (which will be displayed as a section header), and add your properties to the related list at the bottom of the page.

Accessing a properties page

A properties category in and of itself doesn’t do anything for you though. In order for these to be displayed as part of a page you need to create a module that points to the correct URL to include the categories and present them all on one page. This is exactly how the email properties page works. Here’s the module URL…

https://demo.service-now.com/system_properties_ui.do?sysparm_title=Email%20Properties&sysparm_category=Email,POP3,Email%20Security,Email%20Auto%20User,Email%20Advanced

And here’s what that page looks like…

A system properties page URL needs to have 3 different parts…

  1. A pointer to the properties UI page (https://demo.service-now.com/system_properties_ui.do)
  2. A ‘sysparm_title’ parameter to add a title to your page (sysparm_title=Email%20Properties)
  3. A ‘sysparm_category’ parameter to indicate which properties categories should be included in the page (sysparm_category=Email,POP3,Email%20Security,Email%20Auto%20User,Email%20Advanced)

So this example points you to a properties page with a title of ‘Email Properties’ that includes 5 properties categories – ‘Email’, ‘POP3’, ‘Email Security’, ‘Email Auto User’, and ‘Email Advanced’. One thing that I noticed as I tested this is that the ‘%20’ escaping for the spaces in the URL is necessary for this to work properly.

Either way you choose to display your properties, you’ll need to access them in script for them to be of any real use. Here’s how you can do that…

Accessing a property in server-side script (Business Rules, UI Actions, UI Pages, etc.)

//Return the value of the ‘your.property.name.here’ system property

var propertyValue = gs.getProperty('your.property.name.here');

Accessing a property in client-side script (Client Scripts, UI Policies, etc.)

There isn’t a way to directly access a system property in client script and the need to do this is probably extremely rare. If you do have a situation where you need to access a system property in client script you can do so in a few ways.

  1. Add the property to your session client data as shown here.
  2. The nice thing about this method is that you don’t have to do an expensive GlideRecord query to get your property information. It gets added to the client session data when the session is established for a particular user.

  3. Add the property to the ‘g_scratchpad’ object using a ‘Display’ business rule as shown here.
  4. This option is similar to the previous one, but doesn’t set the property for the entire session…just for the table you’re working on.

  5. Create a GlideRecord Query and pull from the ‘sys_properties’ table.
  6. While this method is probably the most familiar to you and seems the simplest, it can also be a huge performance killer. Because of this, this method should only be used if no other method is readily available. Any time you’re going to perform a client-side GlideRecord query, I highly recommend setting your script up to run that query asynchronously as described here.
    You can query for a system property like this…

    var rec = new GlideRecord('sys_properties');
    rec.addQuery('name', 'your.property.name.here');
    rec.query();
    if(rec.next()){
    var yourPropertyValue = rec.value;
    }
By | 2018-07-09T15:00:05-06:00 October 28th, 2010|Categories: System Definition|Tags: , |7 Comments

About the Author:

7 Comments

  1. Alain February 2, 2011 at 7:49 pm - Reply

    Hi there,

    It seems that doing:

    var rec = new GlideRecord(‘sys_properties’);

    rec.get(‘name’, ‘your.property.name.here’);

    in a Client Script does not work anymore… 🙁

    Alain

    • Mark Stanger February 3, 2011 at 12:15 am - Reply

      You’re correct. the ‘get’ method only works client-side if get based on the sys_id of the record. To query using name (or any other attribute) from the client, you need to use the full GlideRecord query syntax. I’ve updated the client script section above to reflect this change.

  2. Sherwin Ghavam February 18, 2015 at 8:11 am - Reply

    in the script there is a small error. line if(rec.next(){ missies a ) so the actual line: if(rec.next()){

    Complete script would be:
    var rec = new GlideRecord(‘sys_properties’);
    rec.addQuery(‘name’, ‘your.property.name.here’);
    rec.query();
    if(rec.next()){
    var yourPropertyValue = rec.value;
    }

    or:
    var rec = new GlideRecord(‘sys_properties’);
    rec.addQuery(‘name’, ‘your.property.name.here’);
    rec.query();
    if(rec.next()) var yourPropertyValue = rec.value;

  3. David January 17, 2017 at 6:48 pm - Reply

    Mark, do you have an example of how to do this in a scoped app? It seems there are many hoops to jump through with a GlideAjax approach and it looks like via the REST API explorer the sys_properties table is not available. Stumped….

    • Mark Stanger January 17, 2017 at 7:14 pm - Reply

      Hey David, It doesn’t surprise me that scoped apps have made this more difficult. I’m not sure off the top of my head what an alternative solution would be but if I think if anything I’ll let you know.

      • David January 17, 2017 at 8:10 pm - Reply

        It appears that I can hit sys_properties table with REST. This works, but I haven’t yet discovered the security ramifications. These properties were created within the same application scope so maybe that has something to do with success so far:

        $scope.query = ‘?sysparm_query=name%3Dx_kasc_ev_charging.session.length&sysparm_fields=name%2Cvalue’;
        $scope.url = ‘/api/now/table/sys_properties’ + $scope.query;

        //CALL TO REST SERVICES (angular)
        //———————
        $http({
        method:’GET’,
        url:$scope.url,
        transformResponse: undefined}).then(function(response) {
        console.log(response.data);
        $scope.data = angular.fromJson(response.data);
        console.log($scope.data[‘result’][0].name);
        }).catch(function(response) {
        console.error(‘Error’, response.status, response.data);
        })
        .finally(function() {
        console.log(“All Done”);
        });
        //———————

        CONSOLE OUTPUT:

        {“result”:[{“name”:”x_kasc_ev_charging.session.length”,”value”:”2″}]}
        x_kasc_ev_charging.session.length
        All Done

Leave A Comment