
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:03 PM
Hello, community.
I have a business rule:
- Query parent record from child
- Get closed date field value
- Add 6 months to closed date (closed date + 6 months)
- Update child due date field value with closed date + 6 months
Looking for script to modify the script: Add 6 months to date, but if result is before today, then add 12 months until result is after today.
var gr= new GlideRecord('u_table_1');
gr.addQuery('sys_id',current.u_parent); //query record number
gr.query();
if(gr.next())
var closed = gr.getValue('u_closed_at');
var gdt = new GlideDateTime(closed);
gdt.addMonthsLocalTime(6);
{
current.u_due_date = gdt;
gr.update();
}
})(current, previous);
Thank you.
Solved! Go to Solution.
Labels:
- Labels:
-
Scripting and Coding
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:22 PM
Try this
var gr= new GlideRecord('u_table_1');
gr.addQuery('sys_id',current.u_parent); //query record number
gr.query();
if(gr.next())
var closed = gr.getValue('u_closed_at');
var gdt = new GlideDateTime(closed);
gdt.addMonthsLocalTime(6);
{
var now = new GlideDateTime(); //now
while(gdt.before(now)){
//As long as gdt is before now then we add 12 months and check again
gdt.addMonthsLocalTime(12)
}
current.u_due_date = gdt;
gr.update();
}
})(current, previous);
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:22 PM
Try this
var gr= new GlideRecord('u_table_1');
gr.addQuery('sys_id',current.u_parent); //query record number
gr.query();
if(gr.next())
var closed = gr.getValue('u_closed_at');
var gdt = new GlideDateTime(closed);
gdt.addMonthsLocalTime(6);
{
var now = new GlideDateTime(); //now
while(gdt.before(now)){
//As long as gdt is before now then we add 12 months and check again
gdt.addMonthsLocalTime(12)
}
current.u_due_date = gdt;
gr.update();
}
})(current, previous);