How to check if any field value changes on the form?

Ipshita Kumari
Kilo Explorer

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

7 REPLIES 7

Hitoshi Ozawa
Giga Sage
Giga Sage

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;
    }
}

lasse3
Mega Guru

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.

This worked like a charm, thanks!