How to check if any field value changes on the form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 12:00 PM
Hi Team,
Hope you all are doing well.
I have requirement to check if any field values have been modified on the form and make "Suggestion" field mandatory if any of the field value changes.
Can you please suggest how can I achieve this requirement ?
Regards,
Ipshita
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 12:06 PM
Hi Ipshita,
You can use below
g_form.modified;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 12:11 PM
If you just want to do a check to see if any value on the entire form changed (a dirty form), you can use ‘g_form.modified’ in an ‘onSubmit’ client script like this…
function onSubmit() {
if(g_form.modified){
return confirm("Values on the form have changed.\nDo you really want to save this record?");
}
}
function onSubmit() {
var field1 = g_form.getControl('caller_id'); //Get the 'Caller' field control
var field2 = g_form.getControl('short_description'); //Get the 'Short description' field control
//See if the 'changed' attribute on either field is true
if(field1.changed || field2.changed){
return confirm("Values on the form have changed.\nDo you really want to save this record?");
}
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 02:08 AM
function onSubmit() {
var field1 = g_form.getControl('caller_id'); //Get the 'Caller' field control
var field2 = g_form.getControl('short_description'); //Get the 'Short description' field control
//See if the 'changed' attribute on either field is true
if(field1.changed || field2.changed){
return confirm("Values on the form have changed.\nDo you really want to save this record?");
}
}
This gives an error - onSubmit script error: TypeError: Cannot read properties of undefined (reading 'changed'):
function () { [native code] }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 12:17 PM
Hello Ipshita,
Refer to this article where there is sample code provided for both client and server side.
https://servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/
Mark the comment as a correct answer and also helpful if this has answered your question.