Set Due Date to be 14 days prior to Go-Live Date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 08:11 AM
I have a custom form that I have setup. I have a custom field on my task that is labeled as "Go-Live Date".
On my subtask, I have a field labeled as "Due Date".
My subtasks are set to auto-generate upon submitting the initial task.
I need the "Due Date" field to auto-set for 14 days prior to the "Go-Live Date" on the parent task.
What is the best way to accomplish this?
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 08:18 AM
Try using the 'addDays' method in GlideDateTime:
GlideDateTime.addDays()
var gdt = new GlideDateTime(<go-live-date>);
// 14 days prior to date
gdt.addDays(-14);
gs.print(gdt.getDate());
Hope that helps!
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 08:18 AM
Hi,
What you need to do is add a couple of lines to the code that is creating the sub task something like this:
var dueDate = new GlideDateTime(go_live_date);
dueDate.addDays(-12);
When your code is implementing the sub task just add in
u_dueDate = dueDate;
before doing the insert.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 08:24 AM
Hi,
You didn't officially state if your "Due Date" field is a date or date/time field, nor did you mention what the "Go-Live Date" field is either (if date or date/time).
For Date:
var gdate = new GlideDate();
gdate.setValue('go_live_field');
gdate.addDays(-14);
current.due_date = gdate;
For Date/Time:
var gdate = new GlideDateTime();
gdate.setValue('go_live_field');
gdate.addDays(-14);
current.due_date = gdate;
Else...if one is one type of field and the other is another type...you have to do more work, but I'll leave that for later, if you need it.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2019 09:09 AM
Sorry for the delay in responding - all of your posts were very helpful. I had since been giving an alternate request on how they want this to generate.
I ended up with 2 custom tables for this task, both extend the "Task" table.
The Parent task in this instance will spawn several sub-tasks & Incidents automatically. Each of the sub-tasks and incidents ended up having different due dates. I had to first write a business rule to query the tables on my incident and sub-tasks and update the "Go-Live Date" and set them according to the "Go-Live Date" on my parent task. These fields will also update anytime the "Go-Live Date" on my parent task is updated. below is an example of that script.
Parent Table
After Insert/update
Condition: Go-Live Date Changes
var gr = new GlideRecord('<target table>');
gr.addQuery('<Parent Table>', current.getValue('sys_id'));
gr.query();
while(gr.next)
{
gr.u_go_live_date = current.go_live_date;
gr.update();
}
Once I had the Go-Live Date updating on all tables then I was able to write a second business rule on the child tables.
After: Insert/Update
Condition: Go-Live Date Changes
var gdt = new GlideDate();
gdt.setValue(current.u_go_live_date);
gdt.addDaysLocalTime(-14);
current.u_date_due = gdt.getDate();
current.update();
I did it this way so that I could customize the Date due on each of the incidents/sub-task that had a different requirement for "date due"
Thank you all for your help.