Catalog UI Policy for restricting dates

matt_a
Kilo Guru

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:

find_real_file.png

 

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?

1 ACCEPTED SOLUTION

matt_a
Kilo Guru

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

View solution in original post

12 REPLIES 12

Allen Andreas
Administrator
Administrator

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!

Hi Allen, would you be able to help me with that script please?

The 2 field names are: start_date and finished_date

Alexey7
Mega Sage

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);

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