Is there a way to detect which fields are being changed from a onSubmit Client Script ?

vinod9
Tera Expert

Hello SN Team,

Can you please tell me, how to identify field value of record changed using onSubmit client script.

@Mohith Devatte 

@Ankur Bawiskar 

Regards

Vinod

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

hey vinod ,

can you tell the exact requirement ?

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should know which field to check and you can use this to check that in onSubmit

var field1 = g_form.getControl('caller_id');

if(field1.changed){
	
}

It's possible in business rule easily

Checking for Modified or Changed Fields in Script

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Here is my code, while changing the view from Cxs_popup view to default view  getting error "onSubmit script error: can not read properties of undefined(reading'changed')".

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var field1 = g_form.getControl('subcategory'); //Get the 'Caller' field control
    var field2 = g_form.getControl('business_service'); //Get the 'Short description' field control
    var field3 = g_form.getControl('urgency');

    
     if (field1.changed || field2.changed ) {
   
        return confirm("Values on the form have changed.\nDo you really want to save this record?");
  
    }

 

is there any other way where we can find out which field value of the record updated.

Note :The code working in sandbox but not in dev

@Ankur Bawiskar 

@vinod

Did you mistakenly marked other response as correct?

The link I shared already talks about g_form.modified logic.

Would you mind marking appropriate response as correct based on timely response?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mohith Devatte
Tera Sage
Tera Sage

hey vinod ,

can you tell the exact requirement ?