gs.getProperty(key, alt) returns the value of a named property as a string. If the property does not exist, it returns the alternate value you pass as the second argument. It runs in server-side scripts such as business rules and script includes, and it keeps a setting out of your code and in a record an administrator can edit.
What gs.getProperty does
The method belongs to the GlideSystem API, which scripts reach through the gs object. It takes a key, which is the name of the property, and an optional alternate value. It returns a String: the stored value when the property is found, or the alternate value when it is not. The second argument is typed as a general object, so pass a string to keep the return type consistent. For the business rule side of this, see business rules explained, and for shared code, script includes explained.
A short example reads the instance address property:
var attachment_link = gs.getProperty('glide.servlet.uri');
gs.info(attachment_link);
The output is the instance URL. That one call shows the whole idea. The script does not hold the address; the platform does, and the script asks for it by name.
The two parameters in full:
| Parameter | Type | Required | Purpose |
|---|---|---|---|
| key | String | Yes | Name of the property to read |
| alt | Object | No | Value returned when the property is not found |
Where the property values live
Properties are records in the System Property table, sys_properties. An administrator opens it by typing sys_properties.list in the navigation filter. Adding a property needs the admin role. For how roles control access to records in general, see instance security and access control.
A property record carries these fields:
| Field | What it holds |
|---|---|
| Name | The property name your script passes as the key |
| Description | A short phrase saying what the property does |
| Type | The data type of the property |
| Choices | Comma-separated values for a choice list; an equal sign separates a display label from the stored value, as in Blue=0000FF |
| Value | The current value |
| Ignore cache | Controls whether a change flushes this property from all server-side caches |
| Private | Keeps the property out of update set imports |
| Read roles | Roles that can read the property |
| Write roles | Roles that can write the property |
Every value comes back as a string
The Value field stores everything as a string, so gs.getProperty() returns strings, whatever the Type field says. A property of type true or false returns the text 'true' or 'false', not a Boolean.
This catches people out in conditions. A check written as if (gs.getProperty('x_snc_example.feature_on')) passes for the text 'false' too, because any non-empty string is truthy in JavaScript. Compare against the text instead:
var enabled = gs.getProperty('x_snc_example.feature_on', 'false') === 'true';
Numbers need the same care. Convert before doing arithmetic:
var limit = parseInt(gs.getProperty('x_snc_example.batch_limit', '50'), 10);
Both snippets pass a default as the second argument, and both default values are strings, which matches the string return type.
Supplying an alternate value
The second argument is the fallback for a missing property. Passing a default means a script on an instance that lacks the property still gets a usable answer, for example one that has not yet received the property through an update set.
var timeoutText = gs.getProperty('x_snc_example.timeout_seconds', '30');
var timeout = parseInt(timeoutText, 10);
Pick a default that is safe if the property is absent, not one that is merely convenient. For another server-side gs method, see gs.getSession() in server scripts.
Setting a property from a script
The counterpart is gs.setProperty(key, value, description). It sets the key to the value and takes a description as its third argument. For changing a value through the form instead of a script, see changing a date format through system properties.
gs.setProperty("glide.foo", "bar", "foo");
gs.info(gs.getProperty("glide.foo"));
The second line logs bar. Setting a system property this way triggers a system-wide cache flush, and performance can suffer while the caches rebuild. That is the practical reason to treat properties as settings that change rarely.
What belongs in a property
Each change or addition flushes the cache so every node in the cluster stays in sync. The flush has a very high performance cost for one to 10 minutes and can potentially cause an outage if done excessively. Configuration that changes more than once or twice a month belongs in a custom table, not in a system property.
So a property suits a switch, a threshold or an address that an administrator sets deliberately and leaves alone. A counter, a last-run timestamp or a working list does not suit one, because scripts would write to it constantly.
Ignore cache and what it changes
Changing any property always flushes the cache for the sys_properties table. The Ignore cache field decides whether the change also flushes the property’s value from the other server-side caches. It is cleared by default, which means all caches are flushed and the current value is reloaded from the database. It is meant for a narrow case: properties that change more frequently than once a month and are stored only in sys_properties.
Naming properties in a scoped application
The name of an application property in a non-global scope carries the application’s scope as a prefix. Use that prefix when a script reads or writes the value through the domain application property API. Some platform properties do not exist on a base instance until someone adds them to sys_properties, so confirm the exact property name in your instance before you rely on it. For the scope concept itself, see application scope explained.
When your script reads such a property, pass the full prefixed name as the key:
var siteName = gs.getProperty('x_snc_example.site_name', 'Default site');
Properties that differ by domain
The base sys_properties table is not domain-separated, so a value there applies across all domains and users. Where domain separation is in use, the platform adds the System Application Property table, sys_application_property, and a value table, sys_application_property_value. The system checks the application property table first and falls back to sys_properties when no match turns up. For the wider concept, see domain separation explained.
Those tables have their own API, GlideApplicationProperty, which needs the Domain Support – Domain Extensions Installer plugin. If the tables are missing on an instance, activating that installer plugin is the step that brings them in. Its getValue(name, domainSysId) method returns a string. With no domain given it uses the session domain. If the application property does not exist it returns the same-named system property, and a child domain without its own value falls back to its parent’s. It throws an exception when the user lacks access to the domain. Its setValue method cannot be called from a different scope. For a scoped application the name carries the scope prefix here too.
The two tables split the work. System Application Property defines each property, with fields for name, description, type, default value, a reference to the matching sys_properties record, usage notes, read roles and write roles. Its name is a unique key. System Application Property Value holds the domain-specific values, with a reference to the application property, the domain, an overrides field and the value itself. The pairing of application property and domain is unique, so a domain carries at most one value for a given property. In the value table, the Expand Domain Scope view lists every override in one place.
A plain example is a first-day-of-the-week setting. The base system might hold Sunday, while a child domain overrides it to Monday and nobody edits a script. That is the purpose of the arrangement: changing application behaviour per domain without new code, overriding system property values for chosen domains, and managing properties at finer granularity in scoped applications.
For an instance without domain separation, gs.getProperty against sys_properties is the whole story.
Frequently asked questions
What does gs.getProperty return if the property does not exist?
It returns the alternate value passed as the second argument. Pass one so the script has a sensible answer on an instance that lacks the property.
Why does my true or false property behave as if it is switched on?
The method returns the text 'true' or 'false', not a Boolean, and a non-empty string counts as truthy. Compare the result with the string 'true'.
Can I use gs.setProperty for a value that changes every day?
That is a poor fit. Setting a system property flushes caches system-wide, and values that change more than once or twice a month are better held in a custom table.
What name do I pass for a property in my own scoped application?
The full name, starting with the application scope, such as x_snc_example.my_setting.
What does the Ignore cache field change?
It decides whether a property change also flushes that property from the other server-side caches. The sys_properties table cache is flushed on any change.