if Planned start date is less than 24ours or outside of 8 pm and 6am make Reason for emer Mandatory
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 12:25 AM - edited 07-17-2024 12:26 AM
In one of the catalog items I have a Planned start date and Reason for emergency change field .
Reason for emergency change should be visible and Mandatory only if Planned start date is less than 24ours from now or outside of 8 pm and 6 am.
How can I achieve this any help will be appreiated.
Thanks
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2024 12:41 AM
Hi @Kishor O Try below onChange Catalog Client Script and modify code accordingly
function onChange(control, oldValue, newValue, isLoading) {
var plannedStartDate = g_form.getValue('planned_start_date');
if (plannedStartDate) {
var plannedStartDateObj = new GlideDateTime(plannedStartDate);
var currentDateObj = new GlideDateTime();
var differenceInHours = gs.dateDiff(plannedStartDateObj, currentDateObj, true);
if (differenceInHours < 24 || isOutsideNightHours(plannedStartDateObj)) {
g_form.setMandatory('reason_for_emergency_change', true);
g_form.setVisible('reason_for_emergency_change', true);
} else {
g_form.setMandatory('reason_for_emergency_change', false);
g_form.setVisible('reason_for_emergency_change', false);
}
}
}
function isOutsideNightHours(dateObj) {
var hour = dateObj.getHourOfDay();
return (hour < 6 || hour >= 20);
}