-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript_code.txt
61 lines (45 loc) · 1.78 KB
/
javascript_code.txt
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
function doGet(e){
Logger.log("--- doGet ---");
var tag = "",
Value = "";
try {
// this helps during debugging
if (e == null){e={}; e.parameters = {tag:"test",Value:"-1"};}
tag = e.parameters.tag;
Value = e.parameters.Value;
// save the data to spreadsheet
save_data(tag, Value);
return ContentService.createTextOutput("Wrote:\n tag: " + tag + "\n Value: " + Value);
} catch(error) {
Logger.log(error);
return ContentService.createTextOutput("oops...." + error.message
+ "\ntag: " + tag
+ "\nValue: " + Value);
}
}
// Method to save given data to a sheet
function save_data(tag, Value){
Logger.log("--- save_data ---");
try {
//var dateTime = new Date();
// Paste the URL of the Google Sheets starting from https thru /edit
// For e.g.: https://docs.google.com/..../edit
//var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/12RCxZo_XW5citKXHGaIWRTgJGPnee17K9DmBI2NlhT0/edit"); //Bus On Time Sheet
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/17SvbLm8hMzeknDUT0BChdnpUK7JxJJea6E06dGONLTQ/edit"); //Check Bus On Time Sheet
var dataLoggerSheet = ss.getSheetByName("5C");
// Start Populating the data
if (tag == "CH-01-AY-7854"){
dataLoggerSheet.getRange("A2").setValue(Value); // Value
}
else if (tag == "CH-04-AG-8512"){
dataLoggerSheet.getRange("B2").setValue(Value); // Value
}
else if (tag == "CH-02-BG-5678"){
dataLoggerSheet.getRange("C2").setValue(Value); // Value
}
}
catch(error) {
Logger.log(JSON.stringify(error));
}
Logger.log("--- save_data end---");
}