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_idorcurrent.getUniqueValue()instead - In Mobile/Service Portal — use
$scope.data.sys_idor the record object directly - When you need the
sys_idof a different record — query that record directly instead
Key behaviors and gotchas
- Returns
nullfor new records, not an empty string — always use!currentSysIdto check for new records - The value persists across form refreshes and field updates, unlike some cached client values
- Available immediately in
onLoadscripts but may benullinonSubmitfor new records being saved - Works across all ServiceNow form factors (desktop, mobile, tablet) unlike some
g_formmethods - 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.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.