To add 4 years to todays year and subtract 1 month present month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2022 11:45 PM
I want update
valid_year = todays year + 4
valid_month=todays month-1
I wrote the following code, but it is not working
var gd = new GlideDateTime(gs.nowDateTime());
//gdt=gd.getYearLocalTime();
gr.u_valid_year = gd.addYearsLocalTime(4);
gr.u_valid_month = gd.addMonthsLocalTime(1);
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2022 11:57 PM
Hi there,
Just running this code:
Evaluator: com.glide.script.RhinoEcmaError: "gr" is not defined.
First thing would be, fix this. Or are you not sharing your full code?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 12:26 AM
var gr = new GlideRecord('u_atm_card_cells');
gr.initialize();
if (!gr.next()) {
gr.newRecord();
gr.u_card_holder_name = current.sys_id;
var gdt = new GlideDateTime();
gr.u_valid_through_year = gdt.addYearsLocalTime(4);
gr.u_valid_through_month = gdt.addMonthsLocalTime(1);
gr.insert();
}
This is my code.I tried your solution but my fields are not getting updated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 12:03 AM
This works fine:
var gdt = new GlideDateTime();
gdt.addYearsLocalTime(4);
gs.print(gdt);
var gdt = new GlideDateTime();
gdt.addMonthsLocalTime(1);
gs.print(gdt);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2022 12:47 AM
Hi
You can use the below script:-
var setYear = new GlideDateTime();
setYear.addYearsLocalTime(4);
var gdt = new GlideDateTime(setYear);
gdt.addMonthsLocalTime(-1);
gs.print(gdt);
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022