What It Does
The setDisplayValue() method parses a date/time string using the current user's display format and timezone settings, then converts it to UTC for internal storage. The method expects the input string to match the user's configured date format (found in System Properties > Localization or user preferences).
ServiceNow performs timezone conversion by first interpreting the string as a local time in the user's timezone, then calculating the equivalent UTC time. The platform uses the user's session timezone (from their user record) or the system default timezone if no user context exists. This conversion happens immediately when the method executes.
The method returns void and modifies the GlideDateTime object in place. If the input string cannot be parsed (invalid format, malformed date, or null/undefined), the method silently fails without throwing an error, leaving the existing GlideDateTime value unchanged. There's no return value indicating success or failure.
Edge cases include handling of daylight saving time transitions and ambiguous times. When setting a time that occurs twice during a fall-back transition, ServiceNow assumes the first occurrence. For spring-forward gaps, the platform adjusts to the next valid time. These behaviors align with Java's timezone handling since ServiceNow runs on the JVM.
This method complements setValue() (which expects UTC strings) and setValueUTC() (which bypasses timezone conversion entirely). Use getDisplayValue() to retrieve the value in display format after setting it.
When to Use This
Use setDisplayValue() when accepting date/time input from users through forms, Service Portal widgets, or any interface where users enter dates in their local format. This includes processing CSV imports where dates are in user-readable format, handling REST API inputs that contain localized timestamps, or setting due dates based on user-provided schedules.
Choose setValue() instead when working with system-generated timestamps or API responses that already contain UTC values. Use setValueUTC() for programmatic date calculations where you're certain the input is already in UTC format. Avoid using setDisplayValue() in scheduled jobs or background processes where user context may be unavailable, as timezone conversion becomes unpredictable.
Return Value
The method returns void and provides no indication of success or failure. The GlideDateTime object is modified in place, with the internal UTC value updated if parsing succeeds. When parsing fails due to invalid input, the object retains its previous value without any error notification.
To verify successful parsing, compare the GlideDateTime's value before and after calling the method, or validate the input string format beforehand. The isValid() method can confirm whether the resulting GlideDateTime contains a valid date after the operation completes.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- No Business Rules, ACLs, or audit entries are triggered since this only modifies a script variable, not database records
- Nothing is written to the database until the GlideDateTime is assigned to a record field and the record is saved
- Performance is fast as it only involves string parsing and timezone calculation without database operations
- User session context is required for accurate timezone conversion; behavior may be inconsistent in background processes
- Date format parsing depends on system properties and user preferences, making results user-specific
- Failed parsing is silent with no error logging, making debugging difficult when incorrect formats are used
- Behavior is identical across Business Rules, Script Includes, and other server-side contexts as long as user session exists