-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.gs
65 lines (62 loc) · 1.73 KB
/
Code.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
/** @OnlyCurrentDoc */
/**
* Main function to be triggered onFormSubmit
* Send a formatted email to an approver
* It collect values from the submittedForm (see bellow)
* @param {e}: event
*
* Columns mapping from the Google Sheet
* 0 Timestamp 1 Email address 2 Approval request
* This function is trigger onFormSubmit
* Version: 1
* Creation Date: May 2021
* Author: Vincent M
*/
/**
* Add custom menu items when opening the sheet.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Time off')
.addItem('Form setup', 'formSetup')
.addItem('Column setup', 'columnSetup')
.addToUi();
}
function autoFillGoogleDocFromForm(e) {
// assume it's the first sheet where the data is collected
var sh = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var last = sh.getLastRow();
var lastcol = sh.getLastColumn();
var Requesteremail = e.values[1];
var RequestContent = e.values[2];
var StartDate = e.values[3];
var EndDate = e.values[4];
var Reason = e.values[5];
var MoreInfo = e.values[6];
// Generate Unique ID
var Uuid = uuid_(lastcol);
// return the URL : apps needs to be deployed
var scriptUri = DEPLOY_ID;
Logger.log('uri: '+scriptUri);
// Append results in the Google Sheet
var array = [ [
Uuid, "NA", "NA",
'=HYPERLINK("'+scriptUri+'?i='+Uuid+'&state=APPROVED&last="&ROW(),"Approve")',
'=HYPERLINK("'+scriptUri+'?i='+Uuid+'&state=DENIED&last="&ROW(),"Deny")',
] ]
Logger.log('array to be inserted in the Sheet last: '+array);
// insert colum 4
var newRange = sh.getRange(last,8,1,5);
Logger.log(newRange.getA1Notation());
newRange.setValues(array);
reviewContent_(
Requesteremail,
RequestContent,
Uuid,
last,
StartDate,
EndDate,
Reason,
MoreInfo
); // TemplateEmail + Recipients settings
}