From 1fd6cd1b898a7cd05d474c73d66a21389626898c Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 13:41:21 +0530
Subject: [PATCH 01/10] detectOldValuenewValueOperation.js
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and return the sysIDs of items which was added/removed.
---
.../detectOldValuenewValueOperation.js | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
new file mode 100644
index 0000000000..a42d2244f0
--- /dev/null
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
@@ -0,0 +1,35 @@
+function onChange(control, oldValue, newValue, isLoading, isTemplate) {
+ if (isLoading) {
+ return;
+ }
+
+
+ var prevValue;
+ if (g_scratchpad.prevValue == undefined)
+ prevValue = oldValue;
+ else {
+ prevValue = g_scratchpad.prevValue;
+ }
+ g_scratchpad.prevValue = newValue;
+
+
+ var oldGlideValue = prevValue.split(',');
+ var newGlideValue = newValue.split(',');
+
+
+ var operation;
+
+ if (oldGlideValue.length > newGlideValue.length || newValue == '') {
+ operation = 'remove';
+ } else if (oldGlideValue.length < newGlideValue.length || oldGlideValue.length == newGlideValue.length) {
+ operation = 'add';
+ } else {
+ operation = '';
+ }
+
+ g_form.clearMessages();
+ g_form.addSuccessMessage('Operation Performed : ' + operation);
+ g_form.addSuccessMessage('OldValue : ' + oldGlideValue);
+ g_form.addSuccessMessage('newValue : ' + newGlideValue);
+
+}
From 3787caeeed04ae2fa36ea9c0790043e168e7a9d1 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 13:55:56 +0530
Subject: [PATCH 02/10] readme.md
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and return the sysIDs of items which was added/removed.
---
.../readme.md | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
new file mode 100644
index 0000000000..05e863d7bd
--- /dev/null
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
@@ -0,0 +1,37 @@
+In Client Scripts, oldValue will display the value of last value/record which is stored in that field.
+For new records, it is generally empty and for existing records it displays the value which is stored after load.
+If we will try to change the value in that field, it will still show oldValue the same value which was there during the load of form.
+
+So, In order to identify the oldValue on change(as it does in business rule(previous)), This script comes handy and also it will
+detect the action performed.
+
+
+This onChange Client script comes handy when dealing with Glide List type fields where we have to change the value
+in that particular field and detect the value before and after change and also detect the operation which was
+performed(addition or removal).
+
+Setup details:
+
+onChange client Script on [incident] table
+Field Name: [watch_list]
+Script: Check [detectOldValuenewValueOperation.js] file
+
+
+Output:
+
+Currently there is no one in the watchlist field:
+
+
+
+Adding [amos.linnan] , It shows the operation was addition, newValue(user's sysId) as well as oldValue(empty)
+
+
+
+Adding 2 users one by one:
+
+
+
+
+Removing 2 at once:
+
+
From 3e27aaa8fdf5c5f926ae97765959280942b5548d Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 15:14:07 +0530
Subject: [PATCH 03/10] detectOldValuenewValueOperation.js
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and returns the display name of users who were added/removed along with name of operation performed.
---
.../detectOldValuenewValueOperation.js | 20 +++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
index a42d2244f0..2db5fd4505 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
@@ -3,7 +3,6 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
return;
}
-
var prevValue;
if (g_scratchpad.prevValue == undefined)
prevValue = oldValue;
@@ -16,7 +15,6 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var oldGlideValue = prevValue.split(',');
var newGlideValue = newValue.split(',');
-
var operation;
if (oldGlideValue.length > newGlideValue.length || newValue == '') {
@@ -27,9 +25,19 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
operation = '';
}
- g_form.clearMessages();
- g_form.addSuccessMessage('Operation Performed : ' + operation);
- g_form.addSuccessMessage('OldValue : ' + oldGlideValue);
- g_form.addSuccessMessage('newValue : ' + newGlideValue);
+ var ajaxGetNames = new GlideAjax('scriptUtil');
+ ajaxGetNames.addParam('sysparm_name', 'getWatchListUsers');
+ ajaxGetNames.addParam('sysparm_old_values', oldGlideValue);
+ ajaxGetNames.addParam('sysparm_new_values', newGlideValue);
+ ajaxGetNames.getXMLAnswer(function(response) {
+
+ var result = JSON.parse(response);
+
+ g_form.clearMessages();
+ g_form.addSuccessMessage('Operation Performed : ' + operation);
+ g_form.addSuccessMessage('OldValue : ' + result.oldU);
+ g_form.addSuccessMessage('NewValue : ' + result.newU);
+
+ });
}
From 22825974cc0f792933063ee1a76bf67a4de6ce77 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 15:20:35 +0530
Subject: [PATCH 04/10] readme.md
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and returns the name of users who were added/removed.
---
.../readme.md | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
index 05e863d7bd..1e61af6595 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
@@ -6,9 +6,7 @@ So, In order to identify the oldValue on change(as it does in business rule(prev
detect the action performed.
-This onChange Client script comes handy when dealing with Glide List type fields where we have to change the value
-in that particular field and detect the value before and after change and also detect the operation which was
-performed(addition or removal).
+This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and returns the display name of users who were added/removed along with name of operation performed.
Setup details:
@@ -21,17 +19,19 @@ Output:
Currently there is no one in the watchlist field:
-
+
-Adding [amos.linnan] , It shows the operation was addition, newValue(user's sysId) as well as oldValue(empty)
-
+
+Adding [Bryan Rovell], It shows the operation was addition, oldValue as 'No record found' as there was no value earlier.New Value shows the name of the user (Bryan Rovell)
+
Adding 2 users one by one:
-
+
Removing 2 at once:
-
+
+
From 6c56488a2df61113cd0488d507bb47cb1719e22a Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 15:23:29 +0530
Subject: [PATCH 05/10] scriptUtil.js
This script include handles the sysIds(oldValue & newValue) of users and returns the display name
---
.../scriptUtil.js | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js
new file mode 100644
index 0000000000..445fc91764
--- /dev/null
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js
@@ -0,0 +1,36 @@
+var scriptUtil = Class.create();
+scriptUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
+
+
+ getWatchListUsers: function() {
+
+ var oldUsers = this.getParameter('sysparm_old_values');
+ var newUsers = this.getParameter('sysparm_new_values');
+
+ var result = {
+ oldU: this._getUserNames(oldUsers),
+ newU: this._getUserNames(newUsers)
+ };
+
+ return JSON.stringify(result);
+ },
+
+ _getUserNames: function(userList) {
+ var names = [];
+
+ var grUserTab = new GlideRecord('sys_user');
+ grUserTab.addQuery('sys_id', 'IN', userList);
+ grUserTab.query();
+ if (grUserTab.hasNext()) {
+ while (grUserTab.next()) {
+ names.push(grUserTab.getDisplayValue('name'));
+ }
+ return names.toString();
+ } else {
+ return 'No record found';
+ }
+
+ },
+
+ type: 'scriptUtil'
+});
From 66f92b7a67a16cb5599001953b024c26dc1e9de3 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 15:25:49 +0530
Subject: [PATCH 06/10] readme.md
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and return the display name of users who were added/removed.
---
.../readme.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
index 1e61af6595..9d4af37fcd 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
@@ -13,6 +13,8 @@ Setup details:
onChange client Script on [incident] table
Field Name: [watch_list]
Script: Check [detectOldValuenewValueOperation.js] file
+Script Include Name: scriptUtil (client callable/GlideAjax Enabled - true), Check [scriptUtil.js] file for script
+
Output:
From 26cdcef68f4e4cac656bec98b12818fef66bd384 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 16:29:21 +0530
Subject: [PATCH 07/10] watchListCandidatesUtil.js
This script include handles the sysIds(oldValue & newValue) of users and returns the display name
---
.../{scriptUtil.js => watchListCandidatesUtil.js} | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
rename Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/{scriptUtil.js => watchListCandidatesUtil.js} (83%)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
similarity index 83%
rename from Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js
rename to Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
index 445fc91764..6705b72d0f 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/scriptUtil.js
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
@@ -1,5 +1,5 @@
-var scriptUtil = Class.create();
-scriptUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
+var watchListCandidatesUtil = Class.create();
+watchListCandidatesUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getWatchListUsers: function() {
@@ -29,8 +29,8 @@ scriptUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
} else {
return 'No record found';
}
-
},
- type: 'scriptUtil'
+
+ type: 'watchListCandidatesUtil'
});
From 299c4d2a440f26aad72d4b665e332d39bbebce26 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 16:31:04 +0530
Subject: [PATCH 08/10] detectOldValuenewValueOperation.js
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and returns the display name of users who were added/removed along with name of operation performed.
---
.../detectOldValuenewValueOperation.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
index 2db5fd4505..87cb6ded61 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js
@@ -25,7 +25,7 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
operation = '';
}
- var ajaxGetNames = new GlideAjax('scriptUtil');
+ var ajaxGetNames = new GlideAjax('watchListCandidatesUtil');
ajaxGetNames.addParam('sysparm_name', 'getWatchListUsers');
ajaxGetNames.addParam('sysparm_old_values', oldGlideValue);
ajaxGetNames.addParam('sysparm_new_values', newGlideValue);
From f47a009b3b65d9c6d6974c25f9d3a6f2b4ff5d56 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 16:31:47 +0530
Subject: [PATCH 09/10] readme.md
This onChange Client script comes handy when dealing with Glide List type fields where we have to detect whether the value was added or removed and returns the display name of users who were added/removed along with name of operation performed.
---
.../readme.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
index 9d4af37fcd..cb2b0e5533 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/readme.md
@@ -13,7 +13,7 @@ Setup details:
onChange client Script on [incident] table
Field Name: [watch_list]
Script: Check [detectOldValuenewValueOperation.js] file
-Script Include Name: scriptUtil (client callable/GlideAjax Enabled - true), Check [scriptUtil.js] file for script
+Script Include Name: watchListCandidatesUtil (client callable/GlideAjax Enabled - true), Check [watchListCandidatesUtil.js] file for script
From 66816519528acb4fcdebcf436eed03b404a24df5 Mon Sep 17 00:00:00 2001
From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com>
Date: Sat, 4 Oct 2025 16:32:31 +0530
Subject: [PATCH 10/10] watchListCandidatesUtil.js
This script include handles the sysIds(oldValue & newValue) of users and returns the display name
---
.../watchListCandidatesUtil.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
index 6705b72d0f..26616d6049 100644
--- a/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
+++ b/Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/watchListCandidatesUtil.js
@@ -15,6 +15,7 @@ watchListCandidatesUtil.prototype = Object.extendsObject(AbstractAjaxProcessor,
return JSON.stringify(result);
},
+
_getUserNames: function(userList) {
var names = [];