Date field increment by 1 year based on other date field

SNow35
Giga Guru

Hi All,

I have a date/time field which has the created date of an item, I want to increment it by one year to specify the eligibility date for the user on portal. I have a script include and the date is populated on the confirm box through catalog client script. Please let me know how to achieve this.

Thanks in Advance

7 REPLIES 7

Onkar Pandav
Tera Guru

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Can you share your script include's function that you get date from once for further modifications.

var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery('cat_item='+itemId+'^sys_created_on>=javascript:gs.beginningOfLast12Months()^requested_for='+userId);
gr.orderByDesc('sys_created_on');
gr.query();
if(gr.next())
{
obj.closedDate = "'" + gr.sys_created_on + "'";

}

now I want to increment the closed date to 1 year from script include and set the value in client script and use it on my alert message

 

Following code will increase sys_created_on date by one year.

var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery('cat_item='+itemId+'^sys_created_on>=javascript:gs.beginningOfLast12Months()^requested_for='+userId);
gr.orderByDesc('sys_created_on');
gr.query();
if(gr.next())
{
  var newDate = new GlideDateTime(gr.sys_created_on);
  newDate.addYearsLocalTime(1);
  obj.closedDate = newDate.toString;
}