Skip to content

Commit 60c29e8

Browse files
Feature/auto populate planned end date (#1930)
* Create README.md * Create autoPopulatePlannedEndDate.js * Create README.md * Create addBusinessDays.js * Update addBusinessDays.js * Update README.md * Update addBusinessDays.js * Update README.md * Update addBusinessDays.js * Update autoPopulatePlannedEndDate.js * Update README.md * Update README.md * Update README.md * Update README.md --------- Co-authored-by: Earl Duque <31702109+earlduque@users.noreply.github.com>
1 parent 6e0420c commit 60c29e8

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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.
2+
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)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//Client script
2+
//Table: Change Request
3+
//UI Type: All
4+
//Type: onChange
5+
//Field: Planned Start Date
6+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
7+
if (isLoading || newValue === '') {
8+
return;
9+
}
10+
var daysToAdd;
11+
if(g_form.getValue('type') =='standard' || g_form.getValue('type') =='normal')
12+
daysToAdd = 3;
13+
else if(g_form.getValue('type') =='emergency')
14+
daysToAdd = 1;
15+
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
16+
ga.addParam('sysparm_name', 'addDays');
17+
ga.addParam('sysparm_days', daysToAdd);
18+
ga.addParam('sysparm_date', newValue);
19+
ga.getXML(processResponse);
20+
21+
function processResponse(response) {
22+
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
23+
g_form.setValue('end_date', answer);
24+
}
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The client callable script includes adds number of business days using the OOB 8-5 weekdays, excluding holidays, schedule
2+
The script includes the sys_id of the OOB schedule, calculates the number of business days, and returns the date.
3+
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)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Takes the number of days as a parameter, and the start date
2+
//Name: addBusinessDays
3+
//Client Callable: checked
4+
var addBusinessDays = Class.create();
5+
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
6+
addBusinessDays.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
7+
8+
addDays: function() {
9+
var days = parseInt(this.getParameter("sysparm_days"));
10+
var startDate = new GlideDateTime(this.getParameter("sysparm_date").toString());
11+
var sd = startDate;
12+
startDate = startDate.getDate();
13+
var time = sd.getTime().getByFormat('HH:mm:ss');
14+
var dur = new GlideDuration(60 * 60 * 1000 * (days * 9));
15+
schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //sys_id of OOB schedule 8-5 weekdays excluding holidays
16+
var end = schedule.add(startDate, dur);
17+
var endDate = end.getDate().getByFormat("MM/dd/yyyy");
18+
var endDateTime = endDate + ' ' + time;
19+
return endDateTime.toString();
20+
},
21+
type: 'addBusinessDays'
22+
});

0 commit comments

Comments
 (0)