- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 04:37 AM - edited 05-19-2023 02:25 AM
End date is greater than OR equal to the Start date, I have used below script its not working for Equal function.
only working on the greater than function.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var end = g_form.getValue('start_date');
var start = g_form.getValue('end_date');
if (end >= start) {
alert("Start date is greater than OR equal to End date.");
g_form.clearValue('end_date');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 02:35 AM
same script just modify
1) onChange client script on End date
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideErrorBox('start_date');
g_form.hideErrorBox('end_date');
if(g_form.getValue('start_date') != '' && g_form.getValue('end_date')){
var start = new Date(g_form.getValue('start_date')).getTime();
var end = new Date(g_form.getValue('end_date')).getTime();
if(end < start){
var message = "Start date should be greater than OR equal to End date.";
g_form.showErrorBox('end_date', message);
g_form.clearValue('end_date');
}
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 04:57 AM
What is your question?
In your script you define variables "end" and "start", but use "beginning" in your comparison.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 05:06 AM
Hi Weird,
I have updated the start, still same error.
My question is
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 06:11 AM
you better use onSubmit client script.
If you use onChange then you need to write 2 onchange. 1 on start and 1 on end
Sample onSubmit script
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.hideErrorBox('start_date');
g_form.hideErrorBox('end_date');
if(g_form.getValue('start_date') != '' && g_form.getValue('end_date')){
var start = new Date(g_form.getValue('start_date')).getTime();
var end = new Date(g_form.getValue('end_date')).getTime();
if(end < start){
var message = '"Start date should be greater than OR equal to End date.';
g_form.showErrorBox('start_date', message);
g_form.showErrorBox('end_date', message);
return false;
}
}
}
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
05-19-2023 02:27 AM - edited 05-19-2023 02:27 AM
Hi Ankur,
Its working fine, but i need Onchange catalog script.
Kindly provide Onchange related one.
Thank you!