diff --git a/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/README.md b/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/README.md new file mode 100644 index 0000000000..5b6175153d --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/README.md @@ -0,0 +1,2 @@ +An onChange client script that calls the script includes one that adds the specified number of business days to the planned start date and autopopulates the planned end date based on the type. +For the client callable script include refer to the README file in the Add Business Days Script include folder. Link: [Add Business Days Script Include](/Server-Side%20Components/Script%20Includes/Add%20Business%20Days/README.md) diff --git a/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/autoPopulatePlannedEndDate.js b/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/autoPopulatePlannedEndDate.js new file mode 100644 index 0000000000..70b4930070 --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Populate Planned End Date/autoPopulatePlannedEndDate.js @@ -0,0 +1,25 @@ +//Client script +//Table: Change Request +//UI Type: All +//Type: onChange +//Field: Planned Start Date +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + return; + } + var daysToAdd; + if(g_form.getValue('type') =='standard' || g_form.getValue('type') =='normal') + daysToAdd = 3; + else if(g_form.getValue('type') =='emergency') + daysToAdd = 1; + var ga = new GlideAjax("addBusinessDays"); //Calling the add business days script include, which is in the Server-Side Components/Script Includes/Add Business Days/addBusinessDays.js + ga.addParam('sysparm_name', 'addDays'); + ga.addParam('sysparm_days', daysToAdd); + ga.addParam('sysparm_date', newValue); + ga.getXML(processResponse); + + function processResponse(response) { + var answer = response.responseXML.documentElement.getAttribute("answer").toString(); + g_form.setValue('end_date', answer); + } +} diff --git a/Server-Side Components/Script Includes/Add Business Days/README.md b/Server-Side Components/Script Includes/Add Business Days/README.md new file mode 100644 index 0000000000..b769e9b42f --- /dev/null +++ b/Server-Side Components/Script Includes/Add Business Days/README.md @@ -0,0 +1,3 @@ +The client callable script includes adds number of business days using the OOB 8-5 weekdays, excluding holidays, schedule +The script includes the sys_id of the OOB schedule, calculates the number of business days, and returns the date. +For the onChange client script, refer to the README file in the Auto-POpulate Planned End Date client script folder. Link: [Auto-Populate Planned End Date Client Script](/Client-Side%20Components/Client%20Scripts/Auto-Populate%20Planned%20End%20Date/README.md) diff --git a/Server-Side Components/Script Includes/Add Business Days/addBusinessDays.js b/Server-Side Components/Script Includes/Add Business Days/addBusinessDays.js new file mode 100644 index 0000000000..0e7b1957ea --- /dev/null +++ b/Server-Side Components/Script Includes/Add Business Days/addBusinessDays.js @@ -0,0 +1,22 @@ +// Takes the number of days as a parameter, and the start date +//Name: addBusinessDays +//Client Callable: checked +var addBusinessDays = Class.create(); +var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); +addBusinessDays.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + + addDays: function() { + var days = parseInt(this.getParameter("sysparm_days")); + var startDate = new GlideDateTime(this.getParameter("sysparm_date").toString()); + var sd = startDate; + startDate = startDate.getDate(); + var time = sd.getTime().getByFormat('HH:mm:ss'); + var dur = new GlideDuration(60 * 60 * 1000 * (days * 9)); + schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //sys_id of OOB schedule 8-5 weekdays excluding holidays + var end = schedule.add(startDate, dur); + var endDate = end.getDate().getByFormat("MM/dd/yyyy"); + var endDateTime = endDate + ' ' + time; + return endDateTime.toString(); + }, + type: 'addBusinessDays' +});