
- 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-20-2019 06:41 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 06:58 AM
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

- 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