How to calculate 6 months from today

sonita
Giga Guru

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var today=new Date();

var month_day = new Array();

month_day[0] = "January";
month_day[1] = "Feburary";
month_day[2] = "March";
month_day[3] = "April";
month_day[4] = "May";
month_day[5] = "June";
month_day[6] = "July";
month_day[7] = "Augest";
month_day[8] = "September";
month_day[9] = "October";
month_day[10] = "November";
month_day[11] = "December";

var today_month = month_day[today.getUTCMonth()];

alert('Today Month'+today_month);


There is a date field on the catalog form. User should not be able to enter a date that is 6 months from today. anything before 6 months is acceptable . Can you help me with my onchange client script please?

 



var start = new Date(g_form.getValue('expiration_date'));
//alert(start);

var selected_month=start.getUTCMonth()+1; //get current month
alert('selected month'+selected_month);


alert(today.getDate());
alert(start.getDate());

if(start >today_month+6)
{

g_form.showFieldMsg('expiration_date','Please select your date','error');
g_form.clearValue('expiration_date');
}

 

4 REPLIES 4

Chalan B L
Giga Guru

you should convert the GlideDate object to a GlideDateTime and use addMonthsLocal() or addMonthsUTC(), then convert back to a GlideDate().

 

var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('number','INC0000055');
inc.query();
var date="";
if(inc.next()){
date=inc.opened_at;
gs.print(date);
var datee = new GlideDate();
datee.setValue(date);
datee.addMonths(6);
gs.print(datee.getDate());
}

 

The same i tried in my script and it worked.

 

Please mark the answer as correct and helpful if it helped you..!!

 

Regards,

Chalan

How do I do that in the catalog form?

Call a script include from onchange client script and tried to write the same piece of code given intitally.

 

Please let me know if you need some help here on this..!!

 

Mark answer as correct and helpful if it helped you..!!!

 

Regards,

Chalan

Can you please help me on the script include and glide Ajax . much appreciated