Date Field cannot be a Future Date not working on Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 08:18 AM
Hi Folks
We have a scenario where user when tries to select a date in future it needs to give an error message to user saying date cannot be in the future. But issue lies is when the user is trying to enter the date through keypad instead of choosing from the calendar picker the though the formatting to right date is happening it still throws an error.
Ex: user type in the date field 8/19/2018 and system formats to the right way 08-19-2018 but still throws error. But works when user types with '-' instead of '/'
Script Include :
var ConfirmDate2= Class.create();
ConfirmDate2.prototype = Object.extendsObject(AbstractAjaxProcessor, {
chkCurrDate : function() {
var start = this.getParameter('sysparm_date');
var currDay = gs.now();
if(start > currDay || start == currDay){
return false;
}
else
{ return true; } } });
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading)
{
if(isLoading)
{
return;
}
//start the validation
if(newValue != '')
{
var ga = new GlideAjax('ConfirmDate2');
ga.addParam('sysparm_name', 'chkCurrDate');
ga.addParam('sysparm_date',g_form.getValue('u_date_of_occurrence'));
ga.getXML(NewParse);
}
function NewParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
alert("Date of Incident cannot be a future date ");
g_form.setValue('u_date_of_occurrence', ''); // Setting the variable as empty
}}}
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 09:53 AM
Hi Abhishek,
Can you check date sent to script include is in which format? Try to give alert and also add log statement
var start = this.getParameter('sysparm_date');
gs.log("start date is: " + start);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader