forked from YoloWingPixie/lsobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.gs
More file actions
152 lines (115 loc) · 4.28 KB
/
Copy pathcode.gs
File metadata and controls
152 lines (115 loc) · 4.28 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/********************************************************************************************************************************
* Copyright 2021 BadMojo11
* https://github.com/BadMojo11
*
* License Info
*
*
* Setup/Config
*
* 1. Copy and overwrite any code in the code.gs file into App Script of your spreadsheet
*
* 2. Enter sheet name where data is to be written in the GLOBAL VARIABLES section
*
* 3. Publish > Deploy as web app
* - Enter Project Version name and click 'Save New Version'
* - Set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously)
*
* 4. Copy the 'Current web app URL' and post this in your LsoBot.ps1 form/script action
*
* 5. Insert column names on your destination sheet matching the parameter names of the data you are passing in (exactly matching case)
*
***************************************************************************************************************************************/
/********************
* GLOBAL VARIABLES *
********************/
// New script property service for handling data
var script_properties = PropertiesService.getScriptProperties();
// Define target sheet - Replace with your target sheet name
var sheet_name = "Grades";
/************
* METHODS *
************/
// Comment out if you do not want to expose get method
function doGet(e){
return handleResponse(e);
}
// Comment out if you do not want to expose post method
function doPost(e){
return handleResponse(e);
}
// Main method: handle response
function handleResponse(e) {
// Prevents overwriting data by preventing concurrent access
var public_lock = LockService.getPublicLock();
// Define lock wait time: currently set to 30 seconds
public_lock.waitLock(30000);
try {
// next set where we write the data - you could write to multiple/alternate destinations
var doc = SpreadsheetApp.openById(script_properties.getProperty("key"));
// Get sheet by name
var sheet = doc.getSheetByName(sheet_name);
// Define header as first row
var headRow = e.parameter.header_row || 1;
// Get header columns
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
// Get next available row in sheet
var nextRow = sheet.getLastRow()+1;
// Create array 'row'
var row = [];
// For statement to loop through header columns
for (i in headers){
// Automatically add timestamp to row if your column is named Timestamp
if (headers[i] == "Timestamp"){
// Add timestamp to the new row
row.push(new Date());
} else {
// Else use the header name to get the data
row.push(e.parameter[headers[i]]);
}
}
//Set values in row
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
// Return JSON success results
return ContentService
.createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
.setMimeType(ContentService.MimeType.JSON);
} catch(e){
// IF error, return error result
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally {
//call reGrade here?
//call function getWire
getWire();
// Release the lock on the sheet
public_lock.releaseLock();
}
}
function getWire() {
// Get the grades sheet - replace with name of your sheet
var grades_sheet = SpreadsheetApp.getActive().getSheetByName('Grades');
// Set these values to match the columns in your sheet
var col_id_comments = "D";
var col_id_wire = "F";
// Get the current row where the edit is happening
var row_id = grades_sheet.getLastRow();
//Get range of comments cell
var commentsCell = grades_sheet.getRange(col_id_comments + row_id);
if (commentsCell.isBlank()){
return;
}
else{
var comments = grades_sheet.getRange(col_id_comments + row_id).getValue();
var wire = grades_sheet.getRange(col_id_wire + row_id);
var strlength = comments.length -1;
var lastChar = comments.charAt(strlength);
if (lastChar=="1" || lastChar=="2" || lastChar=="3" || lastChar=="4"){
wire.setValue(lastChar);
}
else{
wire.setValue("-");
}
}
}