Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Nilesh Pol
Kilo Sage

Have you ever received a sys_id and been asked to investigate a record, but had no idea which table it belonged to?

One of the most common troubleshooting scenarios in ServiceNow is receiving a sys_id without any information about the corresponding table or record.

This often happens during:

  • Integration troubleshooting
  • Log analysis
  • Script debugging
  • Data migration activities
  • Workflow investigations

Use Case: 

Suppose someone shares a sys_id like: 8f3f5d7c1b2c1210d4c5a6b8cc4bcb45

But they don't provide:

  • Table name
  • Record number
  • Application information
Searching manually can be time-consuming, especially in large instances with hundreds of tables and instead of manually checking multiple task tables, you can leverage the Task table hierarchy to locate the record automatically.
The following script can quickly identify the exact table.

 

var id = '0ed1bc259359b110d44f38edfaba10f5';

var t = new GlideRecord('sys_db_object');
t.addQuery('super_class', '!=', '');
t.query();

while (t.next()) {

    try {
        var tableName = t.name.toString();
        var gr = new GlideRecord(tableName);

        if (gr.isValid() && gr.get(id)) {
            gs.print('Table: ' + tableName);
            gs.print('Display Value: ' + gr.getDisplayValue());

            if (gr.isValidField('number')) {
                gs.print('Number: ' + gr.getValue('number'));
            }

            break;
        }
    } catch (ex) {
        // Ignore inaccessible tables
    }
}
​

How the Script Works:
Step 1: Define the Sys ID

Replace the placeholder with the sys_id you want to investigate.

Step 2: Query Available Tables
This retrieves tables that extend another table (have a superclass).
The script will iterate through these tables and attempt to locate the record.
Step 3: Create a GlideRecord for Each Table
A GlideRecord object is dynamically created for each table.
Step 4: Check Whether the Sys ID Exists
The get() method searches for a record matching the supplied sys_id.
If found, the condition evaluates to true.
Step 5: Print the Table Name
 
Sample Output:
Table: change_request
Display Value: Normal Change for Server Upgrade
Number: CHG0030045
1 Comment