- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 10:26 AM
Hi everyone!
I have a date field Due date (due_date) on a custom table. I need to prevent entering a date into this field that is prior to today. To achieve this I've created a client script and an accompanying script include. I believe I am close, anyone see why it's not working? thanks!
my onChange client script is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//make sure they are not asking for a due date in the past (before now)
var ga = new GlideAjax("NowDateCalc"); //name of the called script include
ga.addParam("sysparm_name", "getNow"); //name of the function in the script include
ga.getXML(getDate); //callback function
}
function getDate(response) {
var due_date = g_form.getValue('due_date'); //due_date is the name of the field on the table
var rightNow = response.responseXML.documentElement.getAttribute("answer");
if (due_date < rightNow) {
alert("Due date cannot be earlier than today.");
g_form.setValue('due_date', '');
}
}
and my script include, "NowDateCalc" is:
var NowDateCalc = Class.create();
NowDateCalc.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getNow : function() {
return gs.now();
},
type: 'NowDateCalc'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 11:06 AM
Hi,
You can simply do this with the help of UI Policy itself without much need of any script as shown below:
For example I have done this for Planned End Date on Change Request Table as shown below:
Result:
Post this Alert Message it will clear out the Field Value selected by the User also. Replace your Table Name and Field Name in the UI Policy shown above accordingly. This would work on click itself when the User selects the Date i.e. on Change of the field Value.
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 12:57 AM
Thanks, Shloke. I had the same issue and it is working with your solution(easy and simple). Thanks again

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 06:46 AM
If there is a scriptless solution and a scripted solution to the same problem - take the scriptless solution. That's my #1 recommendation. I strongly advise you take another look at the business I wrote above. It's easier to build, maintain, and survive upgrades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 06:22 AM
HI Shloke ,
I have same requirement but only one change is won't be select current date also , i have only option to select future dates only.
I really appreciate , if you give any solution to show some appearances difference in calendar as future dates some more bright compare to past and current dates .
Thanks in advance ..........
Thanks
Chetan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 03:57 AM
very helpful, thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2017 11:24 AM
thanks Shloke, that's the easiest way...it works!