- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 02:29 AM
Hi Everyone,
I have an use-case where I need to make the duration to be selected after 15 days from the current date. How can I achieve this? Please help!!
Example: If I'm filling this form today, then I want the days from 15 to 29 to be greyed or not possible to select and only days after 15 days user should be able to select.
Regards,
Priya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2022 11:49 PM
Hi,
Please try UI policy if it still not resolved.
1. use relative condition as below and select your date field and give 15 days as shown below.
with this you can select date after 15 days from current date.
Script:
function onCondition() {
alert("Enter valid date, You can select date after 15 days from today");
g_form.clearValue('select_the_duration'); //give your variable name
}
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 05:27 AM
check the condition, or simply put the code which clears the field in Execute if false section.
For condition, you need to check if you are selecting "before" as i shared in one of the screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 11:26 PM
Hi,
put the error box line of code in Execute if false script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 11:34 PM
Hi Ankur,
Thanks for your reply..
Putting error box line of code in execute if false did not work.. What else can I do? Please let me know that..
Regards,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 02:22 AM
Hi,
So you want user to select date 15 days from now?
Then do this
1) create onChange client script on that date variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selectedDate = new Date(newValue);
var todayDate = new Date(); // Now
todayDate.setDate(todayDate.getDate() + 15);
if (selectedDate.getTime() < todayDate.getTime()) {
g_form.clearValue('select_the_duration');
g_form.showErrorBox('select_the_duration', 'Date should be selected 15 days from today');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 02:39 AM
Hi,
Thank you for your response!!
Yes, I want user to select date 15 days from now.
Tried with this, but still I was able to order or submit the form and there was no error message when I selected nearby dates..
Regards,
Priya