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

ChanakyaMekala
Kilo Guru

I have implemented the same requirement. PFB

 

onChange client Script:

 

function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '') {
return;
}


var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateDiff');
ajax.addParam('sysparm_fdt', newValue);
ajax.getXML(doSomething);

function doSomething(response){


var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer <= 0){
alert('Expected Due Date cannot be prior to today\'s date');
g_form.clearValue("expected_due_date");
return false;


}

 

Script Include:

var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getNowDateDiff: function(){
var firstDT = this.getParameter("sysparm_fdt"); //First Date Field
var diff = gs.dateDiff(gs.now(), firstDT, true);
return diff;
}

 

Please mark Correct/  Helpful, if it is so

unfortunately, this wont provide the desired outcome.

The user will set a date in the start_date and I only want the user to select a date within the next 12 weeks from the start_date.

Your code is based of "Todays date" and alerting to the fact that the person has logged a date prior to today

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