Skip to content

Commit bcd0a92

Browse files
committed
Update: Added system field check
1 parent 2b1aa12 commit bcd0a92

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Core ServiceNow APIs/GlideRecord/Compare_2_records/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ It’s useful for debugging, verifying data after imports, or checking differenc
88
## Working
99
The script:
1010
1. Retrieves two records using their `sys_id`.
11+
2. Includes or Excludes the system fields.
1112
2. Iterates over all fields in the record.
1213
3. Logs any fields where the values differ.
1314

@@ -21,7 +22,7 @@ If used in a scoped application, ensure that the target table is accessible from
2122
Run this script in a **Background Script** or **Fix Script**:
2223

2324
```js
24-
compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here');
25+
compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here', false);
2526
```
2627
---
2728
## Example Output

Core ServiceNow APIs/GlideRecord/Compare_2_records/compareRecords.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
/**
22
* Compare two records in a ServiceNow table field-by-field.
33
* Logs all field differences between the two records, including display values.
4-
*
4+
*
5+
* Parameters:
6+
* @param {string} table - Table name
7+
* @param {string} sys_id1 - sys_id of first record
8+
* @param {string} sys_id2 - sys_id of second record
9+
* @param {boolean} includeSystemFields - true to compare system fields, false to skip them
10+
*
511
* Usage:
6-
* compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here');
12+
* compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here', true/false);
713
*/
814

9-
function compareRecords(table, sys_id1, sys_id2) {
15+
function compareRecords(table, sys_id1, sys_id2, includeSystemFields) {
1016
var rec1 = new GlideRecord(table);
1117
var rec2 = new GlideRecord(table);
1218

@@ -21,6 +27,10 @@ function compareRecords(table, sys_id1, sys_id2) {
2127
for (var i = 0; i < fields.size(); i++) {
2228
var field = fields.get(i);
2329
var fieldName = field.getName();
30+
31+
if( !includeSystemFields && fieldName.startsWith('sys_') ) {
32+
continue;
33+
}
2434

2535
var val1 = rec1.getValue(fieldName);
2636
var val2 = rec2.getValue(fieldName);
@@ -40,4 +50,4 @@ function compareRecords(table, sys_id1, sys_id2) {
4050
}
4151

4252
// Example call
43-
compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here');
53+
compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here', false);

0 commit comments

Comments
 (0)