how to achive this requirement can any one help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Desired Date Requested"
- Mandatory
- Date
- Users should not be able to add the current day or next day 2 days and should only be able to select business days only
- Map to Due Date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
what do you mean by business day?
For some customers Saturday and Sunday are business days and for some others it's not.
you can use GlideSchedule in your onChange + GlideAjax
check these 2 links
Variable Date no less than 5 business days
Auto-populating and validating date fields
š” If my response helped, please mark it as correct ā and close the thread šā this helps future readers find the solution faster! š
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
ā Requirement: Restrict Date Field and Map to Due Date
Users should not be able to add:
- The current day or next 2 days
- Weekends (Saturday, Sunday)
They should only be able to select business days, and the selected date should map to the Due Date field.
--------------------------------------------------------------------
š§© Implementation Steps
--------------------------------------------------------------------
Step 1: Create the Date Variable / Field
----------------------------------------
- Variable name: u_due_date
- Type: Date
- Mandatory: true
Step 2: Add Catalog Client Script (onChange)
--------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selectedDate = new Date(newValue);
var today = new Date();
// Remove time
today.setHours(0, 0, 0, 0);
selectedDate.setHours(0, 0, 0, 0);
// Calculate difference in days
var diffDays = Math.floor((selectedDate - today) / (1000 * 60 * 60 * 24));
// Restrict current and next 2 days
if (diffDays <= 2) {
alert("Please select a date at least 3 business days from today.");
g_form.clearValue('u_due_date');
return;
}
// Restrict weekends
var day = selectedDate.getDay();
if (day == 0 || day == 6) {
alert("Weekends are not allowed. Please select a business day (MondayāFriday).");
g_form.clearValue('u_due_date');
return;
}
// Map to Due Date field
g_form.setValue('due_date', newValue);
}
--------------------------------------------------------------------
Step 3: Use for Standard Forms (Optional)
----------------------------------------
Create a Client Script on the table (e.g., Task, Incident) with same logic.
--------------------------------------------------------------------
Step 4: Optional Enhancement
----------------------------------------
You can extend validation to check official holidays via a Script Include referencing cmn_schedule_span.
--------------------------------------------------------------------
ā
Expected Behavior
| Scenario | Result |
|-----------|---------|
| Today | ā Alert |
| Tomorrow / +2 days | ā Alert |
| Weekend | ā Alert |
| Valid business day (+3) | ā
Accepted, auto-mapped to Due Date |
