Why i am getting same alert and error message twice in workspace?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 09:43 PM
I have configured on change client script to clear the dob value and to show alert or error message if the selecting date is in future. I tried with alert and error message both are reflecting twice.
when i tried with field error box its clearing the value first time and showing error box but on same page second time also if i have choose future value its not clearing the value why?
Can i have any inputs on it?
Client script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 05:53 AM
Hi @Hemanth M1.... gone through same feeling!!
Just check below on change modified client script which is working fine in native UI but not working as expected in workspace.
if dob is greater than today date its clearing the value with out error msg.
second time on same page again when i selected future date the value was there at field but not cleared.
The above and this both are very strange to me why this is happening only in workspace.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || newValue == null) {
return;
}
// Type appropriate comment here, and begin script below
var today = new Date();
var dob = new Date(g_form.getValue('date_of_birth'));
var view = g_form.getViewName();
if (today < dob) {
g_form.clearMessages();
g_form.clearValue('date_of_birth');
g_form.showErrorBox('date_of_birth', 'DOB can not be future date!!');
}
else {
return true;
//console.log(newValue);
//alert('Date of birth allows only past date');
//g_form.setValue('date_of_birth','');
//alert('DOB can not be future date!!');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 09:39 AM
Hi @KM SN ,
It a issue with g_form.clearValue('date_of_birth'); statement, workspace considering this is also a change to the field and executing script multiple times,
if you comment this line it works fine but it will not clear the field.
write g_form.clearMessages(); before the if else block (so that it would clear the messages when u change the date form past to future /From future to past
//replace below script in the if block.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2023 10:46 AM
Hi @Hemanth M1
Thanks for inputs but its not a expected behavior.
when i did as you said first time i am getting message and value is clearing whereas second time i am just seeing message but value is not clearing and when i save the record it taking the value which is not a expected thing.
I will be happy if you come up with any more inputs which solve this strange behavior.
Thank You.
Mani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 04:00 AM
Hi @KM SN ,
Would you mind try this solution (i haven't verified )
I still see clearValue, let see how it behaves in UI policy script.
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 03:30 PM
Hi, I have the same issue as well where the onChange script runs twice in configurable workspace but not in backend UI. The issue appears when I clear the same onchange field after some actions being performed. However, when I delay the clearField (for 2 seconds), the onChange does not run twice in workspace. This is the source codes I tried:
if (isLoading || newValue === '') {
return;
}
var setTimer = '';
setTimer = setTimeout(setTimerDelay, 2000);
function setTimerDelay() {
alert('timer waits for 2 sec');
g_form.clearValue(<field_name>);
}
I was literally deleting all codes while trying the clearValue function on the form. 😞