Understanding sys_id’s and Reference Fields

What is a sys_id? In ServiceNow, a sys_id is a unique identifier for a specific record within a table. It is automatically generated by the system and used to identify and reference the record within …

sys_id's in servicenow

Buy The "ServiceNow Developer's Manual" Now

We've packed over a decade of ServiceNow Development advice, into a single e-book.

Buy It Now

What is a sys_id?

In ServiceNow, a sys_id is a unique identifier for a specific record within a table. It is automatically generated by the system and used to identify and reference the record within the table.

sys_id’s are 32 characters long and are always a unique combination of alphanumeric characters, so letters and numbers only.

The sys_id is typically used when building references between tables, or when performing a database query to retrieve a specific record.

Here’s an example of a sys_id:

10af7aec73d4c3002728690c4cf6271c

It is important to note that the sys_id is unique to a given record within a table, and cannot be used to reference records in other tables.

It’s also important to never try to update the sys_id of any record, under any circumstance.

Why Are sys_id’s important?

Every record, on every table, has a unique sys_id.

sys_id’s are only relevant to ServiceNow admins and developers – as the end user has no need to even know that it exists, they just use the number field to differentiate records.

But sys_id’s are important in ServiceNow because they provide a unique and reliable way to identify and reference records within a table. They are used extensively throughout the platform, and are especially important when building relationships between tables, or when performing database queries to retrieve specific records.

To use sys_id’s, you can simply reference the sys_id of a record when building a reference between tables, or when performing a database query. For example, if you wanted to retrieve all records in the Incident table where the caller is a specific user, you could use the sys_id of the user record to specify the caller in your query.

It’s also important to note that the sys_id is typically hidden from view within the ServiceNow user interface, and can only be accessed by using the appropriate APIs or by using the sys_id field in a database query. This helps to ensure that the sys_id is not accidentally modified or deleted, which could cause problems with references and relationships between records.

In summary, sys_id’s are an important part of ServiceNow and provide a unique and reliable way to identify and reference records within a table. They are used extensively throughout the platform and are essential for building relationships and performing database queries.

Reference Fields and sys_id’s

ServiceNow uses a relational database, meaning that records can point to other records in different tables.

For example, when you have an incident, and you point the “Assigned To” field to the User [sys_user] table – then “Assigned To” becomes a reference field, and that value is a sys_id. This would be the value of the user.

In ServiceNow, a reference field is a special type of field that is used to create a relationship between two records in different tables. The reference field contains the sys_id of the related record, which allows the system to link the two records together.

For example, let’s say that you have two tables in ServiceNow: one for Incident records, and another for User records. If you want to create a relationship between an Incident record and the user who reported it, you could create a reference field on the Incident table that contains the sys_id of the related User record. This would allow you to easily retrieve the User record associated with an Incident, and vice versa.

In summary, the relationship between a sys_id and a reference field in ServiceNow is that the sys_id is used to identify and link records together using reference fields. The reference field contains the sys_id of the related record, which allows the system to easily retrieve and display information from the related record.

You can get the sys_id of any record by going to it’s form, and right-clicking on the form header. You’ll there see a drop-down list and you’ll see a “Copy sys_id” option.

Selecting that adds the current records sys_id to the clipboard of your computer.

You can also get it by Showing the XML of any record, and you’ll see that the sys_id is a column on every single table.

How To Use get() In A Script To Retrieve A Record

If you have the sys_id of a record, you can write a simple GlideRecord query, using get() to retrieve that record, and then do something with it.

Take the following example:

// Set the table and sys_id of the record you want to retrieve
var table = 'incident';
var sys_id = 'abc123';

// Retrieve the record
var gr = new GlideRecord(table);
gr.get(sys_id);

// Check if the record was retrieved
if (gr.isValid()) {
  // Do something with the record
  gs.info('Record retrieved: ' + gr.number);
} else {
  gs.error('Record not found: ' + sys_id);
}

In this example, we first define the table and sys_id of the record we want to retrieve. We then use the GlideRecord class to create a new GlideRecord object and retrieve the record using the get() method, passing in the sys_id as an argument. Finally, we check if the record was retrieved successfully, and do something with the record if it was found.

This is just a simple example, but it shows how you can use the sys_id of a record to retrieve it from the database in ServiceNow.

You can then use the retrieved record to perform further operations, such as updating its values or referencing it in other database queries.

This should help you better understand how sys_id’s work and what they truly are.

Let us know what you think about our article on sys_id’s.



What Do You Think About This Article?

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x