Adding and Accessing a System Property

As I’ve indicated in the past, I write this blog at least partially as a way of documenting things that I’ve figured out, but which I know I’ll need to refer back to at a future point. This is one of those things.

When programming my side projects, I use system variables on a regular basis. Having a constant in one spot where I can change it if something about my environment changes is hugely helpful. Likewise, it is very beneficial to be able to have one value for my dev environment and another value when the code is running on the production server.

Creating a system property is the equivalent thing in ServiceNow, and I’m grateful to my previous boss, Chris York, for showing me how to both set one up and then access it from inside of my server-side script include.

To create or modify a system property, go to:

sys_properties.list

Then, if we assume that I set up a system property that is named ‘deans.api.key’, to access it from inside of a server script, I would use:

gs.getProperty(‘deans.api.key’);

This would return the value of the system property, allowing me to assign it to a variable or otherwise use it.

Hugely helpful!

Leave a Reply