Skip to content

Commit 1fd6cd1

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 return the sysIDs of items which was added/removed.
1 parent be1fd1a commit 1fd6cd1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading) {
3+
return;
4+
}
5+
6+
7+
var prevValue;
8+
if (g_scratchpad.prevValue == undefined)
9+
prevValue = oldValue;
10+
else {
11+
prevValue = g_scratchpad.prevValue;
12+
}
13+
g_scratchpad.prevValue = newValue;
14+
15+
16+
var oldGlideValue = prevValue.split(',');
17+
var newGlideValue = newValue.split(',');
18+
19+
20+
var operation;
21+
22+
if (oldGlideValue.length > newGlideValue.length || newValue == '') {
23+
operation = 'remove';
24+
} else if (oldGlideValue.length < newGlideValue.length || oldGlideValue.length == newGlideValue.length) {
25+
operation = 'add';
26+
} else {
27+
operation = '';
28+
}
29+
30+
g_form.clearMessages();
31+
g_form.addSuccessMessage('Operation Performed : ' + operation);
32+
g_form.addSuccessMessage('OldValue : ' + oldGlideValue);
33+
g_form.addSuccessMessage('newValue : ' + newGlideValue);
34+
35+
}

0 commit comments

Comments
 (0)