Help with Flow Designer input variable script for getting current date and adding days to it

jlaue
Kilo Sage

Hello - 

I am trying to get a script to work in a Flow Designer flow, input variable.  I just want to get the current date in the script and then add 60 days to it and return that value, however it keeps returning a null value. 

 

Here is what I have for the script:

 

var date = new GlideDate();
var review = date.addDays(60);

return review;
 
Also tried just new Date();
 
Not sure if this script is wrong or if it just isn't formatted properly to work within Flow Designer.  

Thanks!
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @jlaue ,

 

I think you should use GlideDateTime in these type of scenarios.

Snippet should be something like this-

(function() {
    var gdt = new GlideDateTime();
    gdt.addDaysLocalTime(60);
    return gdt.getDate().toString();
})();

 

 

View solution in original post

4 REPLIES 4

Brian Lancaster
Tera Sage

Are you creating a scripted action for this? If not were are you putting the script in flow designer?

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @jlaue - What are you doing with the date? You can return a string like this:

 

// Create an instance of GlideDateTime to get the current date and time
var gdt = new GlideDateTime();

// Add 60 days to the current date
gdt.addDays(60);

// Format the date
var date = gdt.getDate();
gs.info(date.getByFormat('dd/MM/yyyy'));

 

Community Alums
Not applicable

Hi @jlaue ,

 

I think you should use GlideDateTime in these type of scenarios.

Snippet should be something like this-

(function() {
    var gdt = new GlideDateTime();
    gdt.addDaysLocalTime(60);
    return gdt.getDate().toString();
})();

 

 

Thanks for the quick help!!   I was able to utilize that script to get it to work:

 

jlaue_0-1723038667171.png