nahaku
Board Regular
- Joined
- Mar 19, 2020
- Messages
- 106
- Office Version
- 365
- 2019
- Platform
- Windows
I have a simple "App" in google sheet when they press button it runs random number, then i want to store time and the value what they got in second sheet, as a log what happend.
I am new with scripting and i cannot find anywhere how to write to columns data from script.
Currently it only writes the data in to specified cell, but i want to put new record to new row.
I am new with scripting and i cannot find anywhere how to write to columns data from script.
Currently it only writes the data in to specified cell, but i want to put new record to new row.
JavaScript:
function getRandomInt() {
return Math.floor(Math.random(0) * Math.floor(300));
}
function cleanCellNow() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A2");
cell.setValue("");
}
function logTimeRightNow() {
timezone = "GMT+" + new Date().getTimezoneOffset()/60
var date = Utilities.formatDate(new Date(), timezone, "yyyy-MM-dd HH:mm");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var logData = ss.getSheets()[1];
var logcell = logData.getRange("A2");
logcell.setValue(date);
}
function areYouSearched() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A2");
var resultData = ss.getSheets()[1];
var resultcell = resultData.getRange("B2");
if (getRandomInt() % 2 == 0) {
cell.setValue("Search Now");
resultcell.setValue("Search Now");
logTimeRightNow()
SpreadsheetApp.flush();
Utilities.sleep(5000);
cleanCellNow();
}
else {
cell.setValue("Pass");
resultcell.setValue("Pass");
logTimeRightNow()
SpreadsheetApp.flush();
Utilities.sleep(5000);
cleanCellNow();
}
}