Add 3 months to date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 06:16 AM
Hi All,
I'm struggling to add 3 months to an existing date field. The following code below should look up the user and add 3 months to their eligibility date.
DELSetEligibilityOnAssignment();
function DELSetEligibilityOnAssignment() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', current.assigned_to);
gr.query();
var gdt = new GlideDateTime(gr.u_eligibility_date.getGlideObject());
gdt.addMonths(3);
if (gr.next()) {
if (current.u_reason_for_assigning == 'Lost') {
gr.u_work_notes = "Eligibility date changed on " + current.asset_tag + " for the following reason: " + current.u_reason_for_assigning + ".";
gs.log("Before " + gdt + gr.u_eligibility_date);
gr.u_eligibility_date = gdt;
gs.log("After " + gdt + gr.u_eligibility_date);
gr.u_last_upgrade_date = gs.now();
gr.update();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 06:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 07:26 AM
Thanks Mike.
Unfortunately that does not work for me. Our date field is formatted as 19-Nov-2015

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 07:51 AM
Can you send me the screenshot of the business rule that you created and field that you would like to change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2015 07:55 AM
Hi Mike,
The code in shown above. Basically the field "u_eligibility_date" contains a date in the format of 19-Nov-2015. I just need to add 3 months to that.