Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How do we find out the record, given the sys_id?

upasanamahanta
Mega Contributor

Given a sys_id, how do we find to which record the sys_id belongs to?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

You COULD write a script that goes through sys_db_object and checks each table to see if it can find the record. With over 2,000 tables in a default Helsinki instance, this could take a while. The *untested* script might look something like this:



var mySysId = 'xxxxxxxxxxxxxxxxxxxxx'; // put in your sys_id here


var table = new GlideRecord('sys_db_object');


table.query();



while (table.next()) {


      var gr = new GlideRecord(table.getValue('name'));


      if (gr.get(mySysId)) {


                  gs.log('it looks like it came from ' + gr.getValue('label'));


                  break;


      }


}


View solution in original post

17 REPLIES 17

saschawildg
ServiceNow Employee

Hey Mike,
the code has dependencies to other script includes from the DevTools app.
You can find installation instructions here:

https://www.wildgrube.com/servicenow-devtools

Let me know if it works for you!

Cheers

Sascha

I prefer something I can put into a Fix Script rather than install tools

saschawildg
ServiceNow Employee

In that case I can't convince you of installing CodeSanity either:

https://www.wildgrube.com/servicenow-codesanity

1. Its yet another tool

2. It contains Instance Scan checks - one of them sanctioning fix scripts

😄