Skip to content

Commit 2b1aa12

Browse files
committed
Update: Show backend and display values; add scope note in README
1 parent 517e1ff commit 2b1aa12

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Core ServiceNow APIs/GlideRecord/Compare_2_records/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Compare Two Records Using GlideRecord
1+
# Compare Two Records Using GlideRecord (Global Scope)
22

33
This snippet compares two records from the same table in ServiceNow field-by-field using the **GlideRecord API**.
44
It’s useful for debugging, verifying data after imports, or checking differences between two similar records.
@@ -13,17 +13,22 @@ The script:
1313

1414
---
1515

16+
## Scope
17+
This script is designed to run in the Global scope.
18+
If used in a scoped application, ensure that the target table is accessible from that scope (cross-scope access must be allowed).
19+
1620
## Usage
1721
Run this script in a **Background Script** or **Fix Script**:
1822

1923
```js
2024
compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here');
2125
```
22-
26+
---
2327
## Example Output
2428
```js
2529
short_description: "Printer not working" vs "Printer offline"
2630
state: "In Progress" vs "Resolved"
2731
priority: "2" vs "3"
2832
Comparison complete.
29-
```
33+
```
34+

Core ServiceNow APIs/GlideRecord/Compare_2_records/compareRecords.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Compare two records in a ServiceNow table field-by-field.
3-
* Logs all field differences between the two records.
3+
* Logs all field differences between the two records, including display values.
44
*
55
* Usage:
66
* compareRecords('incident', 'sys_id_1_here', 'sys_id_2_here');
@@ -21,11 +21,18 @@ function compareRecords(table, sys_id1, sys_id2) {
2121
for (var i = 0; i < fields.size(); i++) {
2222
var field = fields.get(i);
2323
var fieldName = field.getName();
24+
2425
var val1 = rec1.getValue(fieldName);
2526
var val2 = rec2.getValue(fieldName);
2627

28+
var disp1 = rec1.getDisplayValue(fieldName);
29+
var disp2 = rec2.getDisplayValue(fieldName);
30+
2731
if (val1 != val2) {
28-
gs.info(fieldName + ': "' + val1 + '" vs "' + val2 + '"');
32+
gs.info(
33+
fieldName + ': Backend -> "' + val1 + '" vs "' + val2 + '", ' +
34+
'Display -> "' + disp1 + '" vs "' + disp2 + '"'
35+
);
2936
}
3037
}
3138

0 commit comments

Comments
 (0)