Easy way to set date/time field to 5 business days in the future

booher04
Tera Guru

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.

 

 

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Please see below useful blog for your requirement.

 

https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad

 

Regards,

Sachin

Shivaa1
Tera Contributor

Thanks for sharing the blog with us, I'm kinda lost too, I needed this.

Vivek Verma
Mega Sage
Mega Sage

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