
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 07:57 AM
I am trying to restrict a date picker on the portal.
I want to stop a user selecting a "finish date" greater than the date selected in the "start date".
I am using the following:
With the following script:
function onCondition() {
alert('Finish date cannot be longer than 12 weeks from the start date');
g_form.setValue('finish_date','');
}
But this doesnt appear to work. Is this due to the condition? If so, is there a better way of doing this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 08:26 AM
i am going to close this thread as direction now different to original path. I will re submit a new thread as the issue appears to be setting the JS Date object in the portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 08:19 AM
Hi,
UI policies don't really work in that way, especially with dates. You'll need to use an onChange Client Script to watch the date field and then trigger script based on what the user inserted.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 01:49 AM
Hi Allen, would you be able to help me with that script please?
The 2 field names are: start_date and finished_date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 08:44 AM
Hi,
you need a 'before' business rule:
(function executeRule(current, previous /*null when async*/) {
// The rightnow stores the current time
var rightnow = new GlideDateTime();
rightnow.addWeeksLocalTime(12); //Add 12 weeks to rightnow
// Create a GlideDateTime object for the finish date
var finishDate = new GlideDateTime(current.finish_date);
// If the finish date is after rightnow, do not write the record to the database
// Output an error message to the screen
if(finishDate.after(rightnow)){
gs.addErrorMessage("Finish date cannot be in more than 12 weeks from now. Your request has not been saved to the database.");
current.setAbortAction(true);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 01:51 AM
Hi, thanks for your response.
I need it to be 12 weeks from the date that they pick in another date picker rather than from right now.
Is you suggestion configurable to allow that?
The 2 fields are: start_date and finish_date
Thanks