Catalog client script for Date validation within 1 year is not working in UI Type 'service portal'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2018 05:27 AM
Hi,
I have a catalog client script for validating date within a year and any selection more than a year from current date should through error msg. It is working fine in UI type 'Desktop' but not in 'Service Portal'.
**********Script follows,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var year = '1';
var startDateStr = g_form.getValue('date');
var startDateNum = getDateFromFormat(startDateStr, g_user_date_format);
var currentDateObj = new Date();
var currentDateStr = formatDate(currentDateObj, g_user_date_format);
var currentDateNum = getDateFromFormat(currentDateStr, g_user_date_format);
var endValue = "";
var y = currentDateObj.getFullYear();
var endYear = parseInt(y)+parseInt(year);
currentDateObj.setFullYear(endYear);
endValue = formatDate(currentDateObj, g_user_date_format);
var endValueNum = getDateFromFormat(endValue, g_user_date_format);
if(startDateNum > endValueNum){
alert('Please enter a date within one year from today');
g_form.setValue('date','');
}
}
What to do to make this script work on Service portal? Plz help.
Thank You!
BP
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2018 05:29 AM
what ui type has set in catalog client script?
is that all? if not mark it as ALL

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2018 05:48 AM
another point here
getDateFromFormat : this does not support on portal .
i am adding one thread here. kindly have a look.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2018 05:57 AM
Updated Script: just give a try.
var date1 = new Date(g_form.getValue('start_date'));
var date2 = new Date();
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(diffDays >= 365) {
alert("Please enter a date within one year from today");
g_form.setValue('start_date','');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 09:23 AM
Refer these below.
https://community.servicenow.com/community?id=community_question&sys_id=0705753fdbe4170c7b337a9e0f96193b
https://community.servicenow.com/community?id=community_question&sys_id=f45a8307db825704032a7a9e0f9619b6
Let me know if you got any difficulties.
- Santa