Verify that duration date is no more than an year from now based on the date of another variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2015 10:06 AM
The user is prompted to enter a date that is no more than a year from now. I need to check that the date is valid when it is entered. Is anyone working on something similar or has a script or business rule doing this already. This is on a service catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2015 11:01 AM
Pablo,
Are you prompting an Input screen where they will set the date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2015 11:51 AM
This a date variable on the form where they select the date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2015 01:24 PM
Pablo,
You can have a Client Script like:
var date = getDateFromFormat(g_form.getValue('<<date>>'),g_user_date_format);
var today = new Date();
if((date.getTime() - today.getTime()) > (364 * 24 * 60 * 60 * 1000))
{
alert('Date should be below one year);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2015 07:43 AM
Hi I have tried the following script and I am having no success for my Date field. I am trying to limit the data to one year or less on my Record Producer Field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var date = getDateFromFormat(g_form.getValue('u_resolution_date'),g_user_date_format);
var today = new Date();
if((date.getTime() - today.getTime()) > (364 * 24 * 60 * 60 * 1000))
{
alert('Date should be below one year');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2016 09:31 AM
Hi guys,
I got the functionality to work through to following Catalogue Client Script: (NB, 'contract_end_date' is the name of my field)
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
if(newValue != '') {
//current date
var currentDateObj = new Date();
var currentDateStr = formatDate(currentDateObj, g_user_date_format);
var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);
//get start date
var startDateStr = g_form.getValue('contract_end_date');
var startDateNum = getDateFromFormat(startDateStr, g_user_date_format);
var today = new Date();
if (startDateNum - today.getTime() > (365 * 24 * 60 * 60 * 1000)) {
alert('Date must be less than one year');
g_form.setValue('contract_end_date', '');
}else{
if (!startDateNum) {
alert('Invalid Date. Please select the date picker and try again.');
g_form.setValue('contract_end_date', '');
}
}
}
}
}
NB: Also, by adding in the following piece of code at the end prevents users entering jargon into the field. (IE, they have to enter a valid date format):
}else{
if (!startDateNum) {
alert('Invalid Date. Please select the date picker and try again.');
g_form.setValue('contract_end_date', '');
}