Search sys_id in entire Servicenow instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 08:15 AM
Hi,
I have a doubt regarding searching records in Servicenow. Given the sys_id and the table, there is a possibility to get the corresponding record. My doubt is given only the sys_id, is it possible to get a record corresponding to the sys_id?
I'm asking this because I read that the sys_id is unique across an instance. So given a sys_id, there must be only one corresponding record in an entire instance.
I'd like to know the possibility using code (Glide API), and searching in UI.
Please assist.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2024 07:31 PM
Assuming that SN Utils is available to a user, this is exactly what the OP asked for. They have a sys_id and want the record that it's associated to. Thanks @Tommy SN Sahlin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2022 10:16 AM
Try this one. I have this script saved in OneNote because I use it at least once a month.
Useful Background Script - Find a record by its sy... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 08:31 AM
Hello balu25int
Maybe you can try to run the following background script, just replace the sys_id and it will search it for you
searchIt('sys_id');
function searchIt(sys_id) {
gs.print('Searching tables for ' + sys_id);
var baseTables
= new GlideRecord('sys_db_object');
baseTables.addEncodedQuery('super_classISEMPTY^nameNOT LIKEts_c_^nameNOT LIKEsysx_^nameNOT LIKEv_');
baseTables.query();
while (baseTables._next()) {
var tableName = baseTables.name;
// Is it a valid sys_id
var sd = new GlideRecord('sys_dictionary');
sd.addQuery('name', tableName);
sd.addQuery('element', 'sys_id');
sd.queryNoDomain();
if(!sd.next()) continue;
// Search the table
var current = new GlideRecord(tableName);
current.addQuery('sys_id', sys_id);
current.queryNoDomain();
if(current._next()) {
gs.print('Found it in ' + current.getClassDisplayValue() + ' [' + current.getRecordClassName() + '] <a href="' + current.getLink() + '" target="_blank" >Link</a>');
break;
}
}
gs.print('End of Search');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 11:55 AM
Can we create a UI action using this code ? And how to make it this way.. like, when user clicks button there should be a pop up asking to enter sysid - And once sysid is entered and submitted.. the respective record should be shown.
Thanks,
VC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 08:32 AM
Use this script to search the specific Class/Table name:
var sysId = "9bf045c54f56ea00c09b01b28110c70b"; //Update your Sys ID
var gr = new GlideRecord('sys_metadata');
gr.addQuery('sys_id',sysId );
gr.addActiveQuery();
gr.query();
gs.log("No of Records matched: "+gr.getRowCount());
while(gr.next())
{
if(gr.sys_id == sysId )
{
gs.log(" SYS ID: " + gr.sys_id + " Class Name: " + gr.sys_class_name);
}
}
Thanks,
Arindam