Skip to content

Commit 3e4b7d7

Browse files
authored
Find sys_id named records (ServiceNowDevProgram#727)
* Create readme.md * Create findSysIdNamedFiles.js * Update findSysIdNamedFiles.js Fixed regex
1 parent bc05ec5 commit 3e4b7d7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Finds values in fields that are pure sys_id's
3+
//
4+
5+
var table = "cmn_location"; // Table to search in
6+
var field = "name"; // Table field to search in
7+
8+
var grTable = new GlideRecord(table);
9+
grTable.query();
10+
var searchresults = "";
11+
while (grTable.next()) {
12+
var fieldvalue=grTable.getValue(field);
13+
if(/^[a-f0-9]{32}$/.test(fieldvalue)) {
14+
searchresults += fieldvalue + ",";
15+
}
16+
}
17+
if( searchresults != "" ) {
18+
gs.info("The following sys-ids were found in the " + table + "." + field + " field:");
19+
gs.info(searchresults);
20+
} else {
21+
gs.info("No Sys-ID based values in " + table + "." + field);
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Find sys_id named records
2+
3+
Use this background script to find records that contain a sys_id value in a specified field (other than the actual sys_id field)
4+
5+
This might for example have happened by accident during migration of data between two ServiceNow instances where referenced records on the target instance were accidentally created due to a Choice action=create setting on a Field Map.
6+
7+
How to use:
8+
9+
Change the "table" and "field" variables to the table and field name you want to search for sys_ids in

0 commit comments

Comments
 (0)