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

Banu1
Mega Expert

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

4 REPLIES 4

Harsh Vardhan
Giga Patron

what ui type has set in catalog client script?

is that all? if not mark it as ALL

Harsh Vardhan
Giga Patron

another point here

 

getDateFromFormat : this does not support on portal .

 

i am adding one thread here. kindly have a look.

 

https://community.servicenow.com/community?id=community_question&sys_id=c7f20ba1dbd8dbc01dcaf3231f96...

 

Harsh Vardhan
Giga Patron

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','');
					
					
				}
				
			}

Santhana Rajhan
Mega Sage

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