Trying to set a due date in Flow Designer to a dynamic date of 7 days before

kdelbridge
Tera Expert

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!

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

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!

View solution in original post

2 REPLIES 2

Allen Andreas
Administrator
Administrator

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!

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.

 

kdelbridge_0-1708110235779.png

 

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.

 

var date = fd_data.trigger.current.closing_date
var gdt = new GlideDateTime ();
gdt.setValue (date);
gdt.addDaysLocalTime (-7);
return gdt.getValue ();
 
THANKS again....MUCH appreciated! I am truly grateful for this community.