- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 10:20 AM
I want to allow user to select date and time if is more than 15 minutes from current date and time. Below onChange client script I am not able to select previous date but I am able to select anytime after current time. I want to allow only to select when time is 15 minutes or more from current time.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var date = new Date();
var sd = new Date(getDateFromFormat(g_form.getValue('date'), g_user_date_time_format));
if (sd < date) {
g_form.clearValue('date);
g_form.showFieldMsg('date', "Start date must be in the future.", 'error');
jslog('txt');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 07:49 AM
Is working but after I submit a form with correct time and go back and change time to less than 15 minutes is updating the form without any error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 10:42 AM
Edited :- it will allow users to select only dates after 15 minutes from current date.
Logic for that :--
var dateTime1 = new GlideDateTime();
dateTime1.addSeconds(900);
if(newValue<dateTime1){
// Your error
}
Assuming your date field is type of 'Date and Time' type.
Regards,
Gunjan
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 11:03 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var date = new GlideDateTime();
date.addSeconds(900);
var sd = new Date(getDateFromFormat(g_form.getValue('date'), g_user_date_time_format));
if (sd < date) {
g_form.clearValue('date);
g_form.showFieldMsg('date', "Start date must be in the future.", 'error');
jslog('txt');
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 11:26 AM
I am getting an error below
Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var date = new GlideDateTime();
date.addSeconds(900);
var sd = new Date(getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format));
if (sd < date) {
g_form.clearValue('start_date');
g_form.showFieldMsg('start_date', "Start date must be in the future.", 'error');
jslog('txt');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 11:35 AM
Oh my mistake
We can't use GlideDateTime in client side.
We need to call the script include and implement the same logic in that. If it satisfies the condition then return false otherwise return true from script include.
Then in If loop of client script we can check if we get false then show error.
Regards,
Gunjan