
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2022 03:40 PM
Hi,
Anyone help me with the below scenario:
I'm trying to add 3 days if the current system time is above 3 PM. Tried addDays and it's not working in the scoped application.
Any suggestions ??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 10:20 PM
Hi,
something like this
var myDate = new GlideDateTime('<your date>');
var gdt = new GlideDateTime();
var time = gdt.toString().split(' ')[1];
var hour = time.split(':')[0];
hour = parseInt(hour);
if(hour > 15){
myDate.addDaysUTC(3);
}
// now use myDate to set the value
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 09:19 PM
Hi,
use this
addDays() is not allowed in scoped app
use addDayUTC()
var gdt = new GlideDateTime();
gdt.addDaysUTC(3);
gs.info(gdt);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 09:28 PM
Hi Ankur,
thankyou for the reply. but my requirement was if the current system is > 3PM then the date field should be updated to 3days from now.
Can you please help me with that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 09:31 PM
the above script will do that
when you use new GlideDateTime() it uses GMT and since you are adding UTC days it works well
var gdt = new GlideDateTime();
gs.info('now time' + gdt);
gdt.addDaysUTC(3);
gs.info('after 3 days time' + gdt);
[0:00:00.067] Script completed in scope x_421457_testing: script
Script execution history and recovery available here
x_421457_testing: now time2022-01-25 05:30:28
x_421457_testing: after 3 days time2022-01-28 05:30:28
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 09:39 PM
but I have to check the current system time is greater than 3 PM that condition is throwing an error in the GlideDateTime object.
if (currentSystemTme > 15) //24hr clock - this condition is not working as expected
then
gdt.addDaysUTC(3);
Thankyou so much for the quick response. Appreciated