var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
Logger.log("hello");
console.log("hello1");
function doPost(e) {
try {
const jsonData = JSON.parse(e.postData.contents);
const column = jsonData.column;
const elapsedTime = jsonData.elapsedtime;
const solution = jsonData.solution;
const lastRow = sheet.getLastRow();
const firstRow = 6;
Logger.log(column);
Logger.log(elapsedTime);
Logger.log(solution);
var found = 0;
for (var row = firstRow ; row <= lastRow ; row++) {
if (solution == sheet.getRange(row,1).getValue()) {
found = 1;
break;
}
}
if (found) {
sheet.getRange(row,column).setValue(elapsedTime);
} else {
sheet.insertRows(6);
var range = sheet.getRange(6,1);
range.setFontColor('white');
range.setValue(solution);
sheet.getRange(6,column).setValue(elapsedTime);
}
return ContentService.createTextOutput(JSON.stringify({ status:"success",message: "Data received and processed." })).setMimeType(ContentService.MimeType.JSON);
} catch (error) {
Logger.log(error.message);
return ContentService.createTextOutput(JSON.stringify({ status:"error",message: error.message })).setMimeType(ContentService.MimeType.JSON);
}