- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2025 09:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:23 AM
If your field or variable has a default value, or is populated via an onLoad script or script UI Policy, then the onChange script will run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:41 AM
when you use onChange client script there is a isLoading variable
If you wish your onChange should run when form loads and also when field/variable changes then you can add your code accordingly
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the form is loading
if (isLoading) {
// Code to execute when the form is loading
// For example, you can set a field value or perform other actions
g_form.setValue('field_name', 'default_value');
return;
}
// Code to execute when the field value changes
if (newValue !== oldValue) {
// Your onChange logic here
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:23 AM
If your field or variable has a default value, or is populated via an onLoad script or script UI Policy, then the onChange script will run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 05:41 AM
when you use onChange client script there is a isLoading variable
If you wish your onChange should run when form loads and also when field/variable changes then you can add your code accordingly
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the form is loading
if (isLoading) {
// Code to execute when the form is loading
// For example, you can set a field value or perform other actions
g_form.setValue('field_name', 'default_value');
return;
}
// Code to execute when the field value changes
if (newValue !== oldValue) {
// Your onChange logic here
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2025 10:10 PM
yes, we are able to change onLoad script runs on onChange client script removing onLoading parameter