- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:23 AM - edited 04-11-2023 02:24 AM
Hi,
On the change form, I'd like an alert for when a date is selected for the planned start/end date that is before the created date of the change. I have an onChange client script but it's not giving me an alert.
This is my current onChange client script for planned start date (same one for planned end date):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var type = g_form.getValue('change_type');
var plannedStart = g_form.getValue('start_date');
var opened = g_form.getValue('sys_created_on');
if (type == 'normal' || type == 'standard' || type == 'emergency') {
if (plannedStart < opened) {
alert('Planned start date cannot be before opened date');
return false;
}
}
}
What's wrong with it? Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 03:22 AM
Hello,
Make sure that created field is displayed in the form and try this script
Nota: in my instance change type field is "type" and not "change_type"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var type = g_form.getValue('type');
var plannedStart = new Date(getDateFromFormat(newValue, g_user_date_time_format));
var opened = new Date(getDateFromFormat(g_form.getValue('sys_created_on'), g_user_date_time_format));
if (type == 'normal' || type == 'standard' || type == 'emergency') {
if (plannedStart < opened) {
alert('Planned start date cannot be before opened date');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:42 AM
Hi @JordyZ ,
Please look into the community post from 2017, whit same requirement as yours: https://www.servicenow.com/community/itsm-forum/planned-start-date-should-be-after-created-date-for-...
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:44 AM
Hi @AndersBGS thanks for replying!
My client script is actually based on the one provided in that 2017 community post, unfortunately it doesn't work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:50 AM
Hi @JordyZ ,
Do you receive any errors? Have you run it through a debugger?
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 03:22 AM
Hello,
Make sure that created field is displayed in the form and try this script
Nota: in my instance change type field is "type" and not "change_type"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var type = g_form.getValue('type');
var plannedStart = new Date(getDateFromFormat(newValue, g_user_date_time_format));
var opened = new Date(getDateFromFormat(g_form.getValue('sys_created_on'), g_user_date_time_format));
if (type == 'normal' || type == 'standard' || type == 'emergency') {
if (plannedStart < opened) {
alert('Planned start date cannot be before opened date');
return false;
}
}
}