Easy way to set date/time field to 5 business days in the future
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 08:09 AM
I have a need to auto populate a date/time variable(requested_by_date) to 5 business days in the future onLoad if a select box variable(environment) is 'Non Production' and the schedule being '8-5 weekdays excluding holidays'. If select box variable(environment) is 'Production' then it needs to be auto populated to 10 business days in the future onLoad.
I am assuming I need an onLoad client script to accomplish this? Do you think a business rule would work better? I've looked through the community and can't seem to find what I'm looking for. I've tried several scripts, script includes and none worked. I'm back to square one. Any ideas would be helpful
These are for catalog items and must work in the Service Portal view as well.
function onLoad() {
//Type appropriate comment here, and begin script below
var sched = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var gtd = new GlideDateTime(sys_created_on);
gdt.addDays(5);
if (variables.environment == 'non production') {
requested_by_date = gdt;
}
}
That's where I got too so far and where I was unsure if I was on the right path.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 10:53 AM
Please see below useful blog for your requirement.
https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 11:09 AM - edited 03-14-2024 02:14 PM
Thanks for sharing the blog with us, I'm kinda lost too, I needed this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 02:12 AM
Hi,
Try the below script
var days = 5;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('sys id of the 24*5 schedule'); // Sys_id of schedule
current.due_date = schedule.add(currentDateTime, dur);
Thanks,
Vivek Verma