- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Khushbu,
1. UI Policy Configuration
- Uncheck:
- Keep:
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:
// your logic
}
3. Recommended (Best Practice)
Use onChange Client Script instead of UI Policy for better control:
if (isLoading || newValue == oldValue) {
return;
}
// your logic here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Khushbu,
1. UI Policy Configuration
- Uncheck:
- Keep:
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:
// your logic
}
3. Recommended (Best Practice)
Use onChange Client Script instead of UI Policy for better control:
if (isLoading || newValue == oldValue) {
return;
}
// your logic here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks, this worked perfectly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @KhushbuP8939482,
You can use the below script for your requirement:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// This condition stops the script from running when the form is loading
if (isLoading || newValue === '') {
return;
}
// Your script logic here
// Example: Show a message when the field changes
g_form.showFieldMsg('your_field_name', 'The value has changed to: ' + newValue, 'info');
}
If you find my answer useful, please mark it as Helpful and Correct. 😊
Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10
