-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.gs
93 lines (71 loc) · 2.19 KB
/
Setup.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Header = {
Timestamp: 'Timestamp',
EmailAddress: 'Email Address',
Name: 'Name',
StartDate: 'Start date',
EndDate: 'End date',
Reason: 'Reason',
AdditionalInformation: 'Additional Information',
UniqueID: "Request ID",
ApprovedBy: 'Approved By',
DeniedBy: 'Denied By',
ApprovalLink: 'Link to Approve',
DenyialLink: 'Link to deny',
};
const Reason = {
Vacation: 'Vacation',
SickLeave: 'Sick leave',
MaternityPaternity: 'Maternity/Paternity',
Breavement: 'Bereavement',
LeaveOfAbsence: 'Leave of absence',
Other: 'Other reason',
};
/**
* Set up the "Request time off" form.
*/
function formSetup() {
let sheet = SpreadsheetApp.getActiveSpreadsheet();
if (sheet.getFormUrl()) {
let ui = SpreadsheetApp.getUi();
ui.alert(
'ℹ️ A Form already exists',
'Unlink the form and try again.\n\n' +
'From the top menu:\n' +
'Click "Form" > "Unlink form"',
ui.ButtonSet.OK
);
return;
}
// Create the form.
let form = FormApp.create('Request time off')
.setCollectEmail(true)
.setDestination(FormApp.DestinationType.SPREADSHEET, sheet.getId())
.setLimitOneResponsePerUser(false);
form.addTextItem().setTitle(Header.Name).setRequired(false);
form.addDateItem().setTitle(Header.StartDate).setRequired(true);
form.addDateItem().setTitle(Header.EndDate).setRequired(true);
form.addListItem().setTitle(Header.Reason).setChoiceValues(Object.values(Reason)).setRequired(true);
form.addTextItem().setTitle(Header.AdditionalInformation).setRequired(false);
}
/**
* Creates an "Approval" and "Notified status" column
*/
function columnSetup() {
let sheet = SpreadsheetApp.getActiveSheet();
appendColumn(sheet, Header.UniqueID);
appendColumn(sheet, Header.ApprovedBy);
appendColumn(sheet, Header.DeniedBy);
appendColumn(sheet, Header.ApprovalLink);
appendColumn(sheet, Header.DenyialLink);
}
/**
* Appends a new column.
*
* @param {SpreadsheetApp.Sheet} sheet - tab in sheet.
* @param {string} headerName - name of column.
*/
function appendColumn(sheet, headerName) {
let range = sheet.getRange(1, sheet.getLastColumn() + 1);
// Create the header header name.
range.setValue(headerName);
}