var ss = SpreadsheetApp.getActiveSpreadsheet(); var Date; var Systolic; var Diastolic; var history; function doGet(e){ if (e.parameter.history == "DisplayData") { return ReadSheetData(e); }} function doPost(e) { addUser(e, sheet); var msg = " "; if (e.parameter.action == 'register') { var user = e.parameter.user; if (ss.getSheetByName(user) == null) { var sheet = ss.insertSheet(user); sheet.appendRow(["Date", "Systolic", "Diastolic"]); msg = "New User Added"; } else { msg = "User already exists"; } } else if(e.parameter.action == 'login') { var user = e.parameter.user; var sheet = ss.getSheetByName(user); if (sheet != null){ msg = "Sheet accessed"; } else { msg = "User not found"; } } addUser(e, user); return ContentService.createTextOutput(msg); } function addUser(e,user) { var sheet = ss.getSheetByName(user); if (sheet) { Date = e.parameter.Date; Systolic = e.parameter.Systolic; Diastolic = e.parameter.Diastolic; sheet.appendRow([Date, Systolic, Diastolic]); } else { Logger.log("Sheet not found for user: " + user);} } function ReadSheetData() { var sheet = ss.getSheetByName(user); var lastRow = sheet.getLastRow(); var valueRange = sheet.getRange(lastRow, 2, 1, 3).getValues()[0]; //start row, start column, end row, end column var outData = []; var date = valueRange[0]; var systolic = valueRange[1]; var diastolic = valueRange[2]; outData.push([date.toDateString(),systolic,diastolic]); var outString = ContentService.createTextOutput(JSON.stringify(outData)); Logger.log(outData); return outString; }