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.

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

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

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

😄