The sys_id field behaves differently than other fields in client-side code. While g_form.getValue('sys_id') returns an empty string for new (unsaved) records, g_form.getUniqueValue() returns null for new records and the actual GUID for saved records. This null-vs-empty-string difference is critical for proper conditional logic, especially when building URLs or making server calls that require a valid record identifier.

When to use this

  • Building URLs that reference the current record (related lists, reports, external integrations)
  • Making GlideAjax calls that need to query related records based on the current record
  • Enabling/disabling UI elements based on whether the record has been saved
  • Storing the record reference in client-side variables for later use in the same session

When NOT to use this

  • In server-side scripts — use current.sys_id or current.getUniqueValue() instead
  • In Mobile/Service Portal — use $scope.data.sys_id or the record object directly
  • When you need the sys_id of a different record — query that record directly instead

Key behaviors and gotchas

  • Returns null for new records, not an empty string — always use !currentSysId to check for new records
  • The value persists across form refreshes and field updates, unlike some cached client values
  • Available immediately in onLoad scripts but may be null in onSubmit for new records being saved
  • Works across all ServiceNow form factors (desktop, mobile, tablet) unlike some g_form methods
  • Returns a 32-character GUID string when the record exists — safe to use directly in URL encoding
⚠️

Never use g_form.getValue('sys_id') as a substitute. It returns an empty string for new records instead of null, breaking conditional logic and causing URLs with empty sys_id parameters to malfunction.

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