- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 12:33 PM
Hello!
I have created a task in my flow and I need to set the Due Date to be 7 days prior to a date that is already defined on my Trigger Record.
Would I need to create a flow variable for this?
I am still working on my scripting, so any help you can offer would be greatly appreciated.
I do know that I want my due date for this task to be 7 days prior to this date that can be pulled from my flow.
- fd_data.trigger.current.target_closing_date
Many thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 07:07 PM - edited 02-15-2024 07:09 PM
Hi,
You can try in-line script for the specific field within the create record action. Is this due date field is a date field or date/time? That could adjust how to do things such as:
//if due date is date/time
var date = fd_data.trigger.current.target_closing_date;
var gdt = new GlideDateTime();
gdt.setValue(date);
gdt.addDays(-7);
return gdt.getValue();
//if due date is date only
var date = fd_data.trigger.current.target_closing_date;
var gdt = new GlideDateTime();
gdt.setValue(date);
gdt.addDays(-7);
return gdt.getDate();
These are just examples, but you'd want to consider leveraging the GlideDate/GlideDateTime APIs: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideDateTimeAPI#r_GDT...
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
02-15-2024 07:07 PM - edited 02-15-2024 07:09 PM
Hi,
You can try in-line script for the specific field within the create record action. Is this due date field is a date field or date/time? That could adjust how to do things such as:
//if due date is date/time
var date = fd_data.trigger.current.target_closing_date;
var gdt = new GlideDateTime();
gdt.setValue(date);
gdt.addDays(-7);
return gdt.getValue();
//if due date is date only
var date = fd_data.trigger.current.target_closing_date;
var gdt = new GlideDateTime();
gdt.setValue(date);
gdt.addDays(-7);
return gdt.getDate();
These are just examples, but you'd want to consider leveraging the GlideDate/GlideDateTime APIs: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideDateTimeAPI#r_GDT...
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
02-16-2024 11:06 AM
Hello Allen,
Thanks so much for your assistance.
When I rant the script provided, I got this error message when the script tried to run after previous task in the flow completed.
I made the adjustment and it WORKED!!!! Here is the final script I ran . The bold red text is the only change I made to what you provided. I saw your name and knew I'd get this to work as I am aware of your amazing abilities within the ServiceNow platform.