how to achive this requirement can any one help me

damodar
Tera Contributor

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
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@damodar 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

MaxMixali
Mega Sage

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 |