How to detect form changes in UI Action

Dev68
Tera Contributor

Hi all, 

Would like to know how we can detect if there is any field change on the form, when a UI action button is clicked. 

I tried to use current.changes(); but this is not supported in UI Action, the same with GlideScriptRecordUtil which is not supported for scoped application. 

 

Regards, 

Ram

1 ACCEPTED SOLUTION

@ram68 

You can use this logic for scoped application

It worked well for me earlier

How to get Changed or Modified Fields in ServiceNow Scoped Apps?

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@ram68 

Can you try this in the client side UI action

Checking for Modified or Changed Fields in Script

var field = g_form.getControl('fieldName');

if(field.changed){
// your logic
}

Regards
Ankur

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

Hi Ankur, 

The UI Action is server side, and also portal facing. So i cant make the client check box checked and hence the g_form. 

is there any other approach, purely server side, or its even if we can detect the form changes with in the portal client or server side. 

@ram68 

in that case you can use GlideScriptRecordUtil which is Server Side utility

var gru = GlideScriptRecordUtil.get(current);

var changedFieldNames = gru.getChangedFieldNames();

var changedFieldNamesarray = j2js(changedFieldNames);

var arrayUtil = new ArrayUtil();

gs.info('length ' + changedFieldNamesarray.length);

Regards
Ankur

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

Tired the above code in UI Action, but getting below error, looks like its not supported for scoped application. 

GlideScriptRecordUtil is not allowed in scoped applications.