So I made a feature to update data that previously submitted. This is to help user if they had mistake in submit the data. Unfortunately the update function doesn’t work. I use google sheet as database. These are my blocks:
And here’s my app script code:
function doPost(e) {
return ceksheet(e);
}
function doGet(e) {
return ceksheet(e);
}
function ceksheet(e){
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName(e.parameter.SH);
//CREATE
if (e.parameter.func == "Create") {
var ts = e.parameter.TIMESTAMP;
var kegiatan = e.parameter.KEGIATAN;
var namasiswa = e.parameter.NAMASISWA;
var kelas = e.parameter.KELAS;
var bacaan = e.parameter.BACAAN;
var ayat = e.parameter.AYAT;
var bulan = e.parameter.BULAN;
var rowData = ([ts,kegiatan,namasiswa,kelas,bacaan,ayat,bulan]);
sh.appendRow(rowData);
}
//Read
if (e.parameter.func == "Read") {
var rg=sh.getDataRange().getValues();
var data="";
for(var row=1;row<rg.length;++row){
data +=rg[row].join(',')+'\n';
}
return ContentService.createTextOutput(data).setMimeType(ContentService.MimeType.TEXT);
}
//Update
if (e.parameter.func == "Update") {
var ts = e.parameter.TIMESTAMP;
var kegiatan = e.parameter.KEGIATAN;
var namasiswa = e.parameter.NAMASISWA;
var kelas = e.parameter.KELAS;
var bacaan = e.parameter.BACAAN;
var ayat = e.parameter.AYAT;
var bulan = e.parameter.BULAN;
var lr= sh.getLastRow();
for(var i=1;i<=lr;i++){
var data_ts = sh.getRange(i, 1).getValue();
if(data_ts==ts){
sh.getRange(i, 2).setValue(kegiatan);
sh.getRange(i, 3).setValue(namasiswa);
sh.getRange(i, 4).setValue(kelas);
sh.getRange(i, 5).setValue(bacaan);
sh.getRange(i, 6).setValue(ayat);
sh.getRange(i, 7).setValue(bulan);
return ContentService.createTextOutput("Data berhasil di Update").setMimeType(ContentService.MimeType.TEXT);
}
}
}
}
I use data in column A which is a timestamp as unique data to match the data I want to change.
I thought that this function didn’t work because the format in column A was a time formatted column while the data type used as a matcher was a string. But when I replace the column A format with text, the function still doesn’t work.
Here’s screenshot of my data:
Here’s video of me trying to change the second to last row data in column F (from 30 to 32) and column G (from index of Juni (6) to Mei (5)):
WhatsApp Video 2024-05-12 at 8.57.31 AM.mp4 - Google Drive
Thank you in advance