how to check if the filed is modified

KhushbuP8939482
Mega Contributor

I need to add the condition in the UI policies that I need to run the script when the field changes not onload of the form, how to achieve this?

3 ACCEPTED SOLUTIONS

pr8172510
Mega Guru

 

Hi Khushbu,

Screenshot 2026-04-13 133546.pngScreenshot 2026-04-13 133656.png


1. UI Policy Configuration

  • Uncheck:

 

 
On load 
 

 

  • Keep:

 

 
On change 
 

This ensures the policy runs only when the field value changes.


2. If you want to strictly check field modification

Add script in UI Policy:

 

 
if (g_form.isFieldModified('your_field_name')) {
// your logic
}
 

 

3. Recommended (Best Practice)

Use onChange Client Script instead of UI Policy for better control:

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == oldValue) {
return;
}

// your logic here
}
 

View solution in original post

Tanushree Maiti
Kilo Patron

Hi @KhushbuP8939482 

 

1)Uncheck the On load option in the UI Policy form.

(When On load is not selected, the UI Policy won’t run automatically when the form loads. Instead, it will only evaluate and trigger when the fields defined in the Conditions section are modified by the user.)

 

2) In the Advanced view, enable the Run scripts option.

Add your logic inside the onCondition() function within the Execute if true field (and the Execute if false field if needed).

If you want the Execute if false script to run when the condition is no longer satisfied, make sure the Reverse if false option is selected.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

Thanks, this worked perfectly

View solution in original post

3 REPLIES 3

pr8172510
Mega Guru

 

Hi Khushbu,

Screenshot 2026-04-13 133546.pngScreenshot 2026-04-13 133656.png


1. UI Policy Configuration

  • Uncheck:

 

 
On load 
 

 

  • Keep:

 

 
On change 
 

This ensures the policy runs only when the field value changes.


2. If you want to strictly check field modification

Add script in UI Policy:

 

 
if (g_form.isFieldModified('your_field_name')) {
// your logic
}
 

 

3. Recommended (Best Practice)

Use onChange Client Script instead of UI Policy for better control:

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == oldValue) {
return;
}

// your logic here
}
 

Thanks, this worked perfectly

Tanushree Maiti
Kilo Patron

Hi @KhushbuP8939482 

 

1)Uncheck the On load option in the UI Policy form.

(When On load is not selected, the UI Policy won’t run automatically when the form loads. Instead, it will only evaluate and trigger when the fields defined in the Conditions section are modified by the user.)

 

2) In the Advanced view, enable the Run scripts option.

Add your logic inside the onCondition() function within the Execute if true field (and the Execute if false field if needed).

If you want the Execute if false script to run when the condition is no longer satisfied, make sure the Reverse if false option is selected.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: