What It Does

The setProperty method creates a new system property or updates an existing one in the sys_properties table. When called, it performs an immediate database operation — either inserting a new record if the property key doesn't exist, or updating the existing record's value and description fields.

ServiceNow's property cache is immediately invalidated when this method executes, forcing a cache refresh on the next property read. This ensures that subsequent calls to gs.getProperty() return the updated value, even within the same transaction. The property becomes available system-wide immediately after the method completes.

The method returns void and provides no indication of success or failure. If the operation fails due to database constraints or permissions, the script will throw an exception rather than returning a status value. All parameter values are converted to strings before storage, regardless of the input type.

Property keys are case-sensitive and must be unique across the entire instance. If you attempt to create a property with a key that matches an existing system property, the existing property's value and description will be overwritten. This behavior makes it possible to accidentally modify critical system configurations.

⚠️

This method can overwrite existing system properties without warning. Always check if a property exists before creating it unless you specifically intend to update an existing value.

Unlike gs.getProperty() which reads from cache, setProperty performs direct database writes. This makes it significantly slower than property reads and unsuitable for high-frequency operations or tight loops.

When to Use This

Use setProperty for application-specific properties that need to be created or updated programmatically during installation, upgrade, or automated configuration processes. This is appropriate for scoped applications that need to establish their own configuration properties or for migration scripts that need to set system-wide settings.

Most property management should happen through the System Properties UI or during application installation. Avoid using this method in business rules or frequently-executed scripts because it bypasses normal change management processes and creates properties that administrators might not know exist. For runtime configuration that changes frequently, consider using custom tables with proper UI pages instead of system properties.

Never use this method to store user-specific data, session information, or values that change frequently. System properties are global, cached, and intended for configuration values that remain relatively stable over time.

Return Value

This method returns void and provides no feedback about the success or failure of the operation. The absence of a return value means you cannot programmatically verify that the property was created or updated without making a subsequent call to gs.getProperty() to confirm the change.

If the operation fails due to insufficient permissions, database constraints, or system errors, the method will throw an exception that halts script execution. Wrap calls in try-catch blocks if you need to handle potential failures gracefully.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

Platform Behavior & Side Effects

  • Business rules on the sys_properties table will fire, including before/after insert and update rules
  • Audit records are created if auditing is enabled on the sys_properties table
  • Property cache is immediately invalidated across all application nodes in the cluster
  • Database write operation occurs immediately, not deferred until transaction commit
  • Performance is significantly slower than property reads due to cache invalidation overhead
  • ACL evaluations occur based on the current user's permissions to the sys_properties table
  • Properties created programmatically do not appear in any specific category in the System Properties UI unless explicitly categorized