Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Find Table Given Sys_Id

G24
Kilo Sage

What are some excellent ways to search through ALL (or most) ServiceNow Tables for a know sys_id value?

 

Such as this one: ae706e530a96001a00120cb31709c1d6

 

1 ACCEPTED SOLUTION

G24
Kilo Sage

The best way, honestly, is to install and use the "SN Utils" utility.

Then you can just type Ctrl + / + sys_id

Example:  / ae706e530a96001a00120cb31709c1d6

And it will take you right to the record in ServiceNow.

Not sure why this is not a built-in function and requires a 3rd party utility.

View solution in original post

7 REPLIES 7

Tushar
Kilo Sage
Kilo Sage

Hi there,

 

something like this ?

function searchSysIDAcrossAllTables(sysID) {
  var allTables = new GlideRecord('sys_db_object');
  allTables.query();
  
  while (allTables.next()) {
    var tableName = allTables.getValue('name');
    var gr = new GlideRecord(tableName);
    if (!gr.isValid()) {
      // Skip invalid tables (e.g., sys_db_object itself)
      continue;
    }
    
    gr.addQuery('sys_id', sysID);
    gr.query();
    
    if (gr.next()) {
      gs.info('Found sys_id ' + sysID + ' in table ' + tableName);
  
    }
  }
}

// Call the function with the known sys_id value you want to search
searchSysIDAcrossAllTables('ae706e530a96001a00120cb31709c1d6');

 

Mark as correct and helpful if it solved your query.

Regards,
Tushar

John Johnson
Kilo Sage

G24, What if you get this?

G24.png

G24
Kilo Sage

The best way, honestly, is to install and use the "SN Utils" utility.

Then you can just type Ctrl + / + sys_id

Example:  / ae706e530a96001a00120cb31709c1d6

And it will take you right to the record in ServiceNow.

Not sure why this is not a built-in function and requires a 3rd party utility.