- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 08:28 AM
Created two Date/time fields in format DD:MM:YYYY HH:mm:ss
End date(DD:MM:YYYY HH:mm:ss) can not be earlier than Start date(DD:MM:YYYY HH:mm:ss)??
Can anyone give script for this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 10:47 PM
Hi @Community Alums ,
If you have any issue on UI policy you can try Onchange client script on end date as below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var start = g_form.getValue('u_start_date'); //add start date field name
if (newValue <= start) {
g_form.addErrorMessage('End Date should be Greater than Start Date ');//add message here
g_form.clearValue('u_end_date'); //add end date field name
}
}
Screenshot:
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:21 AM
Hi @Community Alums ,
you can give .1 hour not 1 hour and remove one oncondition function.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 10:47 PM
Hi @Community Alums ,
If you have any issue on UI policy you can try Onchange client script on end date as below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var start = g_form.getValue('u_start_date'); //add start date field name
if (newValue <= start) {
g_form.addErrorMessage('End Date should be Greater than Start Date ');//add message here
g_form.clearValue('u_end_date'); //add end date field name
}
}
Screenshot:
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 02:23 AM
Hi Pavan
This is not working correctly , If I give start date as march 22 , 2023 and end date as April 6 , 2023 then also it shows error message. but it only shows error msg when user select end date as before march 22, 2023.
Can you give proper answer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 02:46 AM
Hi @Community Alums ,
Try below onchange client script on end date. It will work
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var start = new Date(g_form.getValue('u_start_date')).getTime(); //add your start date name
var end = new Date(g_form.getValue('u_end_date')).getTime();//add your end date name
if (end < start) {
g_form.addErrorMessage('End Date should be Greater than Start Date ');//add message
g_form.clearValue('u_end_date');
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar