- 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-07-2023 05:47 AM
Hi Pavan ,
I Will check This.
But I got the answer with bellow script.
EndDate Date Validation :
On Change Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var tFormat = g_user_date_time_format;
var EndDate = getDateFromFormat(g_form.getValue('EndDate_date'), tFormat);
if (EndDate < StartDate) {
g_form.addErrorMessage("EndDate date should not be before Start date");
g_form.setValue('EndDate_date', '');
}
}
Thank you.