What It Does

The gs.error() method writes messages to the ServiceNow system log at ERROR severity level. When called, it creates a log entry in the System Logs [sys_log] table with severity 'error' and stores the formatted message along with timing, user context, and script location metadata.

ServiceNow's logging framework processes the message through its substitution engine, replacing numbered placeholders with the provided parameters. The platform automatically escapes HTML entities and special characters to prevent log injection attacks. The final formatted message gets written to both the database log table and any configured external log collectors.

The method returns void and never throws exceptions, even if the logging system fails. Script execution continues normally after calling gs.error(). This makes it safe to use for defensive logging without worrying about breaking business logic flow.

ERROR level messages have special platform behavior compared to other log levels. Many ServiceNow monitoring tools and alerting systems default to watching for ERROR entries. In production environments, ERROR logs often trigger notifications to system administrators and can influence health dashboards and SLA calculations.

The method belongs to the same logging family as gs.info(), gs.warn(), and gs.debug(). All use identical parameter substitution syntax but differ in severity level and platform handling. ERROR sits at the highest severity, making it the most visible in monitoring systems.

When to Use This

Use gs.error() for unexpected failures that indicate something is genuinely wrong but don't require halting execution. Examples include failed external API calls, missing expected configuration data, invalid user input that can't be processed, or database operations that should have succeeded but didn't. These are conditions that operations teams need to know about but that your script can work around or handle gracefully.

Don't use gs.error() for expected business logic conditions or validation failures that users might trigger through normal application use. Use gs.info() or gs.warn() instead. Also avoid it when you need to actually stop execution - gs.error() logs and continues, it doesn't throw exceptions or halt processing.

A common misuse pattern is logging every validation error as ERROR level. Reserve ERROR for system-level problems, not user-level problems. Form validation failures, missing required fields, or permission denials are normal application behavior and should use lower severity levels that don't trigger production alerts.

Return Value

The method returns void (undefined in JavaScript terms). There is no return value to capture or check. The method performs its logging operation as a side effect and provides no feedback about whether the logging succeeded or failed.

Because logging failures are handled silently by the platform, your script won't know if disk space issues, database problems, or permission restrictions prevented the log entry from being written. This fire-and-forget design ensures that logging problems never break business logic, but means you can't programmatically verify that important error messages were successfully recorded.

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

  • Creates a new record in the System Logs [sys_log] table with severity 'error' and current timestamp
  • Triggers any configured log forwarding to external SIEM or monitoring systems
  • May activate email notifications or alerts if instance has ERROR-level log monitoring configured
  • Does not trigger Business Rules, ACLs, or other record-based security mechanisms
  • Performance impact is minimal - logging operations are asynchronous and don't block script execution
  • Log entries include automatic context like current user, session ID, and script execution location
  • Behaves identically across all server-side contexts - Business Rules, Script Includes, Scheduled Jobs, etc.