Allowing Only Current and Future Dates in ServiceNow
- nathanlee142
- May 12
- 4 min read
Updated: May 13

In the dynamic world of ServiceNow, ensuring data integrity is paramount. A common requirement is to restrict users from selecting past dates in certain date fields, allowing only the current date and any date in the future. This ensures that records reflect accurate and forward-looking information. If you've encountered this need, this article will guide you through a straightforward method using ServiceNow's powerful UI Policies.
Why Limit Date Selection in ServiceNow?
Restricting date selections to the current date and future dates can be crucial in various ServiceNow scenarios. For example, you might want to:
Prevent users from setting a task's start date in the past.
Ensure that a policy effective date is not before the current day.
Limit the selection of a future event date.
By implementing this restriction, you can maintain data accuracy, prevent potential errors, and enforce business rules effectively within your ServiceNow instance.
Implementing the Restriction with UI Policies
While client-side scripting can achieve this, ServiceNow best practices often recommend using UI Policies for form validations. UI Policies run on the server-side, making them more robust and less prone to inconsistencies.
Here's how you can configure a UI Policy to allow only the current date and future dates in a specific date field:
Step-by-Step Guide:
Let's assume you have a date field on a form (for example, a field named effective_date) where you want to enforce this restriction. Follow these steps to create a UI Policy:
Navigate to UI Policies: In your ServiceNow instance, navigate to System UI > UI Policies.
Create a New UI Policy: Click the New button to create a new UI Policy.
Configure the UI Policy:
Table: Select the table that contains the date field you want to restrict (e.g., your custom table or a standard table like 'Incident').
Short description: Provide a descriptive name for your UI Policy (e.g., "Restrict Effective Date to Current and Future").
Active: Ensure the Active checkbox is selected.
Apply to all views: Check this box if you want the restriction to apply to all form views. Otherwise, select the specific views where you need this validation.
When to Apply: In the Condition builder, define the condition that should trigger this policy. In most cases, you might want this policy to always be active when the form is loaded or when the date field value changes. You can leave the condition empty if you want it to always apply.
Set the Condition (Crucial Step): This is where you define the logic to check if the selected date is in the past.
Click the "Add filter condition" button.
Select your date field (e.g., effective_date) from the first dropdown.
Choose is less than from the operator dropdown.
In the value field, select Date and then choose Today. This condition will be true if the selected date in your field is before the current date.
Configure the Script: Now, you'll write a script that will execute when the condition in your UI Policy is met (i.e., when a past date is selected).
Navigate to the Run script tab.
Ensure the Execute if true checkbox is selected.
In the Script field, enter the following code:
function onCondition() {
g_form.clearValue('effective_date');
// Replace 'effective_date' with the actual name of your date field
alert('The date value cannot be before the current date. Please
select the current date or a future date.');
}
function onReverse() {
// This function is executed when the condition is no longer true.
// You might not need to do anything here for this specific
requirement.
}
Explanation of the script:
g_form.clearValue('effective_date');: This line clears the value of your date field, forcing the user to select a new date. Remember to replace 'effective_date' with the actual field name in your instance.
alert('The date value cannot be before the current date. Please select the current date or a future date.');: This line displays an informative message to the user, explaining why their selected date was invalid.
Save the UI Policy: Click the Save button to save your newly created UI Policy.
Practical Application:
Imagine you are managing project tasks in ServiceNow. You have a field called "Planned Start Date". By implementing the UI Policy described above on this field, you can prevent users from accidentally setting a start date in the past, ensuring that project timelines are always forward-looking.
Considering Client Scripts:
While UI Policies are generally preferred for this type of validation, you could also achieve a similar result using a client script with the onChange function. However, client scripts run on the user's browser and can sometimes be bypassed or affected by browser settings. UI Policies offer a more secure and reliable approach for enforcing such data constraints.
Conclusion: Ensuring Data Accuracy with Date Restrictions
By implementing a UI Policy to restrict date selections in ServiceNow, you can significantly improve the accuracy and reliability of your data. This method provides a user-friendly way to guide users towards selecting valid dates, preventing errors and ensuring that your ServiceNow records reflect timely and relevant information. Take the time to implement this solution on your relevant date fields to maintain the integrity of your ServiceNow data.