I want to take the Created Date and add the days stored in date Pill

Allen12
Tera Guru

I am working in Flow Designer and want to take the created date and add Data Pill which contains Days to it.

 

Allen12_0-1674506135506.png

and add

Allen12_1-1674506185308.png contains (0, 30, 60, 120, 150)

I want to do this in a Flow Variable

Allen12_2-1674506267424.png

 

Can this be done w/o scripting?  What is the best way to accomplish this?

 

 

 

1 ACCEPTED SOLUTION

Hello,

 

For setting the flow variable via script, you'd click the script button at the end of the field and then create a GlideDateTime object, set the value using your date/time, then addDays with your other field value. Refer to documentation for overall approach: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideDateTimeAPI#r_GDT... 

 

Example would roughly be:

var gdt = new GlideDateTime();
gdt.setValue(fd_data.walk_to_datetime_pill);
var num = Number(fd_data.walk_to_stringfield_that_has_number); //only need to use this if the number captured is in a string field instead of an integer
gdt.addDays(num);
return gdt.getDate(); //or use getValue() if you want the date and time

Please adjust the above as needed.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hello,

You'd have to use script for this.

 

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen,

 

Can you help me with the script?

Hello,

 

For setting the flow variable via script, you'd click the script button at the end of the field and then create a GlideDateTime object, set the value using your date/time, then addDays with your other field value. Refer to documentation for overall approach: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideDateTimeAPI#r_GDT... 

 

Example would roughly be:

var gdt = new GlideDateTime();
gdt.setValue(fd_data.walk_to_datetime_pill);
var num = Number(fd_data.walk_to_stringfield_that_has_number); //only need to use this if the number captured is in a string field instead of an integer
gdt.addDays(num);
return gdt.getDate(); //or use getValue() if you want the date and time

Please adjust the above as needed.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!