- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 04:03 AM
Hi Team,
As per my requirement,
when the priority is changing on the change form,
1. condition = when priority is 1
planned start date and planned end date only allows past date
2. condition= when priority is 2, 3 or 4
planned start date and planned end date only allows future date
how to achieve this?
Regards,
Abhilasha G T
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 06:12 AM
you will require onChange client script on Priority
Something like this, please enhance it further as per your requirement
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('planned_start_date');
g_form.hideFieldMsg('planned_end_date');
// Get the planned start and end date fields
var plannedStartDate = g_form.getValue('planned_start_date');
var plannedEndDate = g_form.getValue('planned_end_date');
// Convert dates to JavaScript Date objects
var startDate = new Date(plannedStartDate);
var endDate = new Date(plannedEndDate);
var currentDate = new Date();
// Condition for Priority 1
if (newValue == '1') {
if (startDate > currentDate || endDate > currentDate) {
g_form.showFieldMsg('planned_start_date', 'Planned start date must be in the past for Priority 1', 'error');
g_form.showFieldMsg('planned_end_date', 'Planned end date must be in the past for Priority 1', 'error');
g_form.clearValue('planned_start_date', '');
g_form.clearValue('planned_end_date', '');
}
}
// Condition for Priority 2, 3, or 4
if (newValue == '2' || newValue == '3' || newValue == '4') {
if (startDate < currentDate || endDate < currentDate) {
g_form.showFieldMsg('planned_start_date', 'Planned start date must be in the future for Priority 2, 3, or 4', 'error');
g_form.showFieldMsg('planned_end_date', 'Planned end date must be in the future for Priority 2, 3, or 4', 'error');
g_form.clearValue('planned_start_date', '');
g_form.clearValue('planned_end_date', '');
}
}
}
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
01-01-2025 06:12 AM
you will require onChange client script on Priority
Something like this, please enhance it further as per your requirement
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('planned_start_date');
g_form.hideFieldMsg('planned_end_date');
// Get the planned start and end date fields
var plannedStartDate = g_form.getValue('planned_start_date');
var plannedEndDate = g_form.getValue('planned_end_date');
// Convert dates to JavaScript Date objects
var startDate = new Date(plannedStartDate);
var endDate = new Date(plannedEndDate);
var currentDate = new Date();
// Condition for Priority 1
if (newValue == '1') {
if (startDate > currentDate || endDate > currentDate) {
g_form.showFieldMsg('planned_start_date', 'Planned start date must be in the past for Priority 1', 'error');
g_form.showFieldMsg('planned_end_date', 'Planned end date must be in the past for Priority 1', 'error');
g_form.clearValue('planned_start_date', '');
g_form.clearValue('planned_end_date', '');
}
}
// Condition for Priority 2, 3, or 4
if (newValue == '2' || newValue == '3' || newValue == '4') {
if (startDate < currentDate || endDate < currentDate) {
g_form.showFieldMsg('planned_start_date', 'Planned start date must be in the future for Priority 2, 3, or 4', 'error');
g_form.showFieldMsg('planned_end_date', 'Planned end date must be in the future for Priority 2, 3, or 4', 'error');
g_form.clearValue('planned_start_date', '');
g_form.clearValue('planned_end_date', '');
}
}
}
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
01-01-2025 07:03 PM
Hope you are doing good.
Did my reply answer your question?
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
01-10-2025 03:53 AM
Hope you are doing good.
Did my reply answer your question?
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
01-01-2025 07:12 AM
Hi @Abhilasha G T ,
You can use GlideDate() functionality using an On change client script and Script include.
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.