Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An onChange client script that calls the script includes that adds the X number of business days to the planned start date, and autopopulates the planned end date based on the type
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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.
Original file line number Diff line number Diff line change
@@ -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'
});
Loading