- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 02:40 PM
Hello,
I have a question regarding the getDateFromFormat function. I need to ensure that the date entered is at least 7 days out from the current date this is what i have right now
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
g_form.hideFieldMsg('date', true);
return;
}
//Check if date is less than 7 days away from now
var disc = getDateFromFormat(newValue, g_user_date_format);
var now = new Date();
var durationInSec = (disc - now)/1000;
if(durationInSec < (7*24*3600)){
g_form.setValue('date', '');
g_form.showFieldMsg('date', "A minimum of 7 days notice is required to process this request", 'error');
}
}
however I get the following error in my log "Error while running Client Script "Validate need by date is at least 7 days": ReferenceError: getDateFromFormat is not defined"
Is getDateFromFormat not already defined for me? im using Istanbul .
any help would be amazing, sorry if im missing something super easy.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 04:40 PM
Please check these on how to calculate and set the date difference, if this helps..
Need help with Date Validation script
Prevent user from entering an End Date that is 7 days greater than Start Date
Set date field compared to another date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 02:56 PM
please check if this helps.
http://wiki.servicenow.com/index.php?title=Validate_Date_and_Time#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 03:13 PM
How would this solve the error im getting ? im pretty new to servicenow sorry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 04:40 PM
Please check these on how to calculate and set the date difference, if this helps..
Need help with Date Validation script
Prevent user from entering an End Date that is 7 days greater than Start Date
Set date field compared to another date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2017 03:26 PM
Are you sure that the function getDateFromFormat() does exists? Try looking at the Wiki and see if there is a function that can help you:
http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#gsc.tab=0
