Date field increment by 1 year based on other date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 11:52 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 12:10 AM
Hi,
Below article will help you on this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 12:13 AM
Hi,
Can you share your script include's function that you get date from once for further modifications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 03:03 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 07:45 AM
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;
}