top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

Understanding sys_id and current in GlideRecord Queries in ServiceNow

Updated: Mar 29


ServiceNow developers frequently use GlideRecord to query, manipulate, and manage records dynamically. Two key concepts that often cause confusion among newcomers are the sys_id and current object in GlideRecord queries. This article aims to clarify these essential components, providing practical examples and explanations tailored to users who seek a deeper understanding of GlideRecord functionality.


What are sys_id and current in GlideRecord?

sys_id is a unique identifier automatically assigned to every record within ServiceNow tables. It's essentially the primary key that distinguishes each record, ensuring uniqueness and easy retrieval.

current refers to a GlideRecord object available within scripts like Business Rules, UI Actions, or Script Includes. Unlike a typical GlideRecord object, which could refer to multiple records, the current object specifically references the single record that triggered the script.


Common Usage and Practical Examples

Using sys_id in GlideRecord Queries

When using GlideRecord, queries often target specific records by their sys_id. Here's a straightforward scenario:

Example: Retrieve user information based on the sys_id of the caller in an incident record.

var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', current.caller_id);
userGr.query();

if (userGr.next()) {
  current.department = userGr.department;
  current.update();
}

In this example, we:

  • Accessed the sys_user table.

  • Used the sys_id from the incident's caller to find the specific user.

  • Updated the incident's department based on the retrieved user's department.


Understanding the current Object

The current object provides direct access to the fields of the record currently in context. Typically, this is the record that activated the script, such as when a business rule runs due to a record being created or updated.

Example: Automatically updating a record upon creation:

(function executeRule(current, previous /*null when async*/) {
  current.short_description = 'Automatically updated';
  current.update();
})(current, previous);

In this scenario, current directly refers to the record being acted upon, allowing seamless updates or manipulations.


Alternative Approaches

Apart from directly querying via sys_id, developers may also leverage:

  • Dot-walking: To directly access referenced fields without additional GlideRecord queries.

  • Script Includes: To encapsulate reusable GlideRecord logic across various scripts.

These approaches optimize your scripts and maintain efficient performance.


Conclusion

Understanding the use of sys_id and the current object significantly enhances your ability to write efficient, powerful scripts in ServiceNow. sys_id offers precise identification for records, while current provides immediate context for dynamic record manipulation. By mastering these concepts, developers can streamline scripting efforts, enhance script clarity, and ensure reliable performance in ServiceNow applications.

Regular practice and real-world scenarios are the best way to deepen your understanding of these essential scripting tools.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page