- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 07:56 AM
Hello all,
I will appreciate if anyone can collaborate providing some ideas on how to add years to a Date Field (Certification Expiration) from a Date Field (Date Trained). I have tried the following but it is not working(Certification Expiration field stays blank after saving request):
1. Right click on the 'Valid Field'
2. Click on personalize Dictionary
3. On default Value tabs, write the script below (ensure that the 'Use dynamic default is unchecked) :
javascript: var dat = new GlideDate(); dat.setValue(gs.monthsAgo(-12));
dat.getDisplayValue();
or
javascript: var dat = new GlideDateTime('u_date_trained');
dat.setValue(gs.monthsAgo(-12));
dat.getDisplayValue();
or
javascript: var dat = new GlideDateTime(); dat.addYears(2);
dat.getDisplayValue();
4. Save
Again, I will greatly appreciate if anyone has an idea to make this calculation.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 09:18 AM
this code worked for me in before update business rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var d1 = new GlideDate();
d1.setValue(current.u_d1);
var yr = d1.getYearNoTZ();
yr = yr + 1;
var s1 = d1.getValue();
s1 = yr+s1.substring(4);
current.u_d2 = s1;
})(current, previous);
result:
Hope this helps.
Thanks,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 08:10 AM
Hi,
try below code. It worked for me.
var d1 = new GlideDate();
gs.print(d1);
var yr = d1.getYearNoTZ();
yr = yr + 1;
var s1 = d1.getValue();
s1 = yr+s1.substring(4);
d1.setValue(s1);
gs.print(d1);
output:
*** Script: 2018-09-14
*** Script: 2019-09-14
Not sure if this is best way but it works
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 08:48 AM
Hello Ali,
I added this into a Business Rule and tried to get the value to the Certification Expiration Date (u_cert_exp_date) and it stays blank. Cannot use on Client Script since cannot use gs. Can you show me how to get the value to show on the field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 08:58 AM
Hello,
please let me know the field types you are using.
Thanks,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 09:02 AM
u_date_trained is Date as well as u_cert_expiration_date.
Thanks!