-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppScriptCode.js
53 lines (47 loc) · 1.74 KB
/
AppScriptCode.js
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
function doPost(request){ // DoPost in order to get postData
var resultObject = JSON.parse(request.postData.contents);
var result = processResult(resultObject);
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
function processResult(resultObject)
{
// Open Google Sheet using ID
// https://developers.google.com/sheets/api/guides/concepts Spreadsheet -> Sheet -> Cell
var spreadSheet = SpreadsheetApp.openById("YOUR ID");
var sheet;
if (resultObject.Platform == "Android"){
sheet = spreadSheet.getSheetByName("AndroidCodeConverter-DontEdit")
} else{
sheet = spreadSheet.getSheetByName("CodeConverter-DontEdit")
}
var result = {"LanguageFile": "FAILED", "Line": "Unknown Failure"};
try{
// Get a cell value from a sheet
var rowData = sheet.getRange(resultObject.Line,resultObject.Language).getValue()
var fileName = "";
if (resultObject.Platform == "Android"){
fileName = sheet.getRange(8,resultObject.Language).getValue()
} else{
fileName = sheet.getRange(2,resultObject.Language).getValue()
}
result = {"LanguageFile": fileName, "Line": rowData};
}catch(exc){
// If error occurs, throw exception
result = {"LanguageFile": "FAILED", "Line": exc};
}
// Return result
return result;
}
function test(){
var Line = 25
var Language = 10
var myJSObject='{"Line": "' + Line +
'", "Language": "' + Language +
'"}';
// Line doesnt need "" since it's an integer
var result = processResult(JSON.parse(myJSObject))
console.log(result)
}
// https://script.google.com/macros/s/AKfycbxPJWHbUPFfZjXSvKMaGEujGP5IP-IulfC-WIsOc5JCjGUCX37GgkFPqvIUvW0Y4H2HGw/exec