Application Automation · Topic 2 of 4
Application Properties
ServiceNow CAD application properties: create scoped properties, set type and read and write roles, show them on a page, read them with gs.getProperty.
- 4 min
- Application properties are system properties created inside the application's scope.
- Names begin with the scope namespace, such as
x_acme_travel.max_trip_cost. - Read with
gs.getProperty('name', 'default')on the server.
What it is
An application property is a named setting stored as a system property record and owned by the application. Scripts read it at runtime, so an admin can change the application's behavior without editing code.
Typical uses are thresholds, email addresses, on and off switches and outside system URLs. Anything that differs between instances or may change over time belongs in a property, not hard coded in a script.
How it works
Creating a property
Create the property as an application file in Studio or App Engine Studio, with the application selected. The property is then part of the application and moves with each published version.
The property name begins with the scope namespace, for example x_acme_travel.max_trip_cost. That prefix keeps names unique and marks the property as the application's own.
| Field | Purpose |
|---|---|
| Name | Unique key, beginning with the scope namespace |
| Description | What the setting does; shown to admins |
| Type | Kind of value, such as string, integer, true or false, or a choice list |
| Value | The current setting |
| Read roles | Who can view the property; empty means all users can read it |
| Write roles | Who can change or delete the property |
Set Write roles to the application's admin role when only app admins should change the value.
Reading a property in a script
Server scripts read properties with gs.getProperty(). The second argument is a default returned when the property does not exist.
var limit = parseInt(gs.getProperty('x_acme_travel.max_trip_cost', '5000'), 10);
if (current.estimated_cost > limit) {
current.needs_approval = true;
}
The value comes back as a string, whatever the property type. Convert numbers with parseInt and compare true or false properties with the string 'true'.
if (gs.getProperty('x_acme_travel.notify_manager') == 'true') {
gs.eventQueue('x_acme_travel.request.submitted', current, current.manager);
}
Giving admins a place to edit
Properties can be grouped into a category and shown together as a properties page. Add a module to the application menu that opens that page, and restrict the module to the app admin role.
This keeps configuration inside the application's navigation. Admins never need to search the full system property list.
Properties on the client
Client scripts cannot call gs.getProperty(), because gs is a server object. To use a property value in the browser, pass it from the server.
| Approach | When |
|---|---|
Display business rule fills g_scratchpad | Value needed when the form loads |
| GlideAjax call to a client-callable script include | Value needed after a field changes |
Choosing a property over other options
| Requirement | Best fit |
|---|---|
| Admins change a limit without a developer | Application property |
| A fixed value used in one script, never changed | Variable in the script |
| A list of rows with several fields each | A table, not a property |
| Turn a feature on or off per instance | true or false property |
How the exam asks about this
- "Admins must change the approval threshold without editing scripts." Store it in an application property and read it with gs.getProperty().
- "Only app admins may change the property." Set Write roles to the app admin role.
- "A client script needs the property value when the form opens." Read it in a display business rule and pass it in g_scratchpad.
What to remember for the exam
- Application properties are system properties created inside the application's scope.
- Names begin with the scope namespace, such as
x_acme_travel.max_trip_cost. - Read with
gs.getProperty('name', 'default')on the server. - Values come back as strings; convert or compare as strings.
- Read roles and Write roles control who can view and change the property.
- A category and a module give admins a properties page inside the app.
gs.getProperty() is server side only. An answer that calls it from a client script is wrong; pass the value with g_scratchpad or GlideAjax.
Common mistakes
Hard coding values that admins will want to change. Every change then needs a developer and a new application version. Put the value in a property.
Comparing a true or false property with the boolean true. The value is the string 'true', so a strict boolean comparison fails.
Creating the property with the application picker on Global. It is then not part of the scoped application and will be missing where the application is installed.
Check yourself
What does the second argument of gs.getProperty() do?
It is the default value returned when the property does not exist, so the script still has a usable value.
Which property field limits who can change the value?
Write roles; only users with one of the listed roles can change or delete the property.
How can a client script use an application property?
A display business rule or a GlideAjax script include reads it on the server and passes the value to the browser.
Topic 2 of 4 in Application Automation
Test yourself on Application Automation
The full ServiceNow CAD question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by ServiceNow. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.