Skip to content

Commit 3e27aaa

Browse files
authored
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.
1 parent 3787cae commit 3e27aaa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Client-Side Components/Client Scripts/Detect oldValue newValue and Operation in Glide List Type Fields/detectOldValuenewValueOperation.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
33
return;
44
}
55

6-
76
var prevValue;
87
if (g_scratchpad.prevValue == undefined)
98
prevValue = oldValue;
@@ -16,7 +15,6 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
1615
var oldGlideValue = prevValue.split(',');
1716
var newGlideValue = newValue.split(',');
1817

19-
2018
var operation;
2119

2220
if (oldGlideValue.length > newGlideValue.length || newValue == '') {
@@ -27,9 +25,19 @@ function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2725
operation = '';
2826
}
2927

30-
g_form.clearMessages();
31-
g_form.addSuccessMessage('Operation Performed : ' + operation);
32-
g_form.addSuccessMessage('OldValue : ' + oldGlideValue);
33-
g_form.addSuccessMessage('newValue : ' + newGlideValue);
28+
var ajaxGetNames = new GlideAjax('scriptUtil');
29+
ajaxGetNames.addParam('sysparm_name', 'getWatchListUsers');
30+
ajaxGetNames.addParam('sysparm_old_values', oldGlideValue);
31+
ajaxGetNames.addParam('sysparm_new_values', newGlideValue);
32+
ajaxGetNames.getXMLAnswer(function(response) {
33+
34+
var result = JSON.parse(response);
35+
36+
g_form.clearMessages();
37+
g_form.addSuccessMessage('Operation Performed : ' + operation);
38+
g_form.addSuccessMessage('OldValue : ' + result.oldU);
39+
g_form.addSuccessMessage('NewValue : ' + result.newU);
40+
41+
});
3442

3543
}

0 commit comments

Comments
 (0)