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 01:11 PM
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.
Following will check if there was any change and make field "Suggestion" mandatory when there was a change.
function onSubmit() {
if (g_form.modified) {
g_form.setMandatory('suggestion', true);
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2021 08:07 AM
Just wanted to add, that if you want to check if a field is changed in a workspace, you can use
if(g_form.isUserModified('field_name')){
// apply logic
}
Make sure to set UI type to "Mobile / Service Portal" as this will otherwise cause errors in the classic UI.
Alternativtly make sure to implement a logic that makes sure that g_form.isUserModified() is a function before executing the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2022 03:15 PM
This worked like a charm, thanks!