How to restrict user to select only 3days from date of request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 11:25 PM
I have date field in catalog item, i need to restrict user to select only any of the date within 3 days from date of request.
And also wish to restrict user in selecting previous date from current date.
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 11:55 PM
Hello @Sachin G K1 ,
For the date validations, you can refer this article.
If this solves your query, mark this as helpful and correct.
Regards
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 11:59 PM - edited 03-16-2023 12:01 AM
1.You have to use addDays() method to add 3 days in current date field and check diff, if diff is more than 3 clear the date value and add field error message.
2.To avoid previous date to be selected use gs.dateDiff() method if diff is -1 then the selected date will be past so you can throw field error message
Refer below link-
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594663
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 12:22 AM
you can use UI policy with no scripting.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 12:35 AM
Hi @Sachin G K1,
You have to use the UI policies for this.
UI policy Condition 1: Date variable BEFORE Today
Execute if true:
function onCondition() {
g_form.clearValue("date_variable");
g_form.showFieldMsg("date_variable", "Previous date not allowed" , "error");
}
UI policy Condition 2: Date variable RELATIVE after 3 days From now
Execute if true:
function onCondition() {
g_form.clearValue("date_variable");
g_form.showFieldMsg("date_variable", "Date variable date should be not be more than 3 days from now, "error");
}
Thanks,
Sagar Pagar