- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 02:18 PM
I have a flow that is taking a date with time, and I'm trying to add a day to it in a cycle so that it can create one for each day of the week, but also is checking this against another flow to make sure that it is a business day and not a holiday. The subflow is also used for time so the time matters too. I have the following and when I use this it ends up changing the time to UTC, which is five hours later, and then will sometimes fail due to time of day. Is there a different way I should be formatting this? I've tried a few versions like .addDaysLocalTime() and a few other things, but maybe there is something else I'm doing wrong. Thank you for any tips!
var returnDate = new GlideDateTime();
returnDate.setDisplayValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getDisplayValue();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 04:17 PM
Hi @Travis Michigan ,
It could be because 'fd_data.flow_var.date' retrieves the time in the system timezone and you are using it as the 'display value'.
You should be able to fix this by either:
- change 'fd_data.flow_var.date' to 'fd_data.flow_var.date.getDisplayValue()', OR
- Use the system timezone instead across the script. i.e.
var returnDate = new GlideDateTime();
returnDate.setValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getValue();
Personally, I prefer using the system timezone but that's just me 🙂
Hope it helps, thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 03:39 PM - edited 02-08-2024 03:40 PM
Hi @Travis Michigan ,
You can add the time zone parameter to variable "returnDate" as below.
Check if it works for you.
var returnDate = new GlideDateTime();
returnDate.setDisplayValue(fd_data.flow_var.date);
returnDate.addDays(1);
var tz = Packages.java.util.TimeZone.getTimeZone('America/New_York'); // set the timezone
returnDate.setTZ(tz);
return returnDate.getDisplayValue();
Refer some guidelines
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 04:17 PM
Hi @Travis Michigan ,
It could be because 'fd_data.flow_var.date' retrieves the time in the system timezone and you are using it as the 'display value'.
You should be able to fix this by either:
- change 'fd_data.flow_var.date' to 'fd_data.flow_var.date.getDisplayValue()', OR
- Use the system timezone instead across the script. i.e.
var returnDate = new GlideDateTime();
returnDate.setValue(fd_data.flow_var.date);
returnDate.addDays(1);
return returnDate.getValue();
Personally, I prefer using the system timezone but that's just me 🙂
Hope it helps, thanks