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