Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Adding one day to a date variable in flow designer

DanielCordick
Mega Patron

I have to add 1 day to a date field in flow designer and feed the new date into my powershell scripts.. so if date on my effective date is  08-27-2021 i need it to be set to  08-28-2021 in my flow, script below not working 

 

any help would be great 

 

var effectiveDate = fd_data.trigger.current.u_effective_date;

var gdt = new GlideDateTime(effectiveDate);
  
  var newDate = gdt.addDaysLocalTime(1);

  return newDate;

this does not work get an error: 

Exception setting "Date": "Cannot convert null to type "System.DateTime"."


 

1 ACCEPTED SOLUTION

had to rewrite the entire thing after getting undefined when i sent it to the logs.

 

 
var effectiveDate = fd_data.trigger.current.u_effective_date.getDisplayValue();

gs.info("EFFECTIVE DATE: " + effectiveDate);

var gd = new GlideDate();

  gd.setValue(effectiveDate);

  gd.addDaysLocalTime(1);
  
  gs.info("NEW DATE: " + gd)

  return gd;​

View solution in original post

4 REPLIES 4

asaunders12
Tera Contributor
The error would make me assume, something is not being set correctly for the effectiveDate variable. Do you get a date when you log that variable or null?

had to rewrite the entire thing after getting undefined when i sent it to the logs.

 

 
var effectiveDate = fd_data.trigger.current.u_effective_date.getDisplayValue();

gs.info("EFFECTIVE DATE: " + effectiveDate);

var gd = new GlideDate();

  gd.setValue(effectiveDate);

  gd.addDaysLocalTime(1);
  
  gs.info("NEW DATE: " + gd)

  return gd;​

Had to do this but with years! Worked GREAT! TY! use (gd.addYearsLocalTime)

DScroggins
ServiceNow Employee

Hello,

 I do not believe you need to specify current when calling fd_data.trigger. Please try the following:

var effectiveDate = fd_data.trigger.u_effective_date.toString();

Hope this helps.

--David