0% found this document useful (0 votes)
10 views2 pages

Spreadsheet CRUD Operations

The document defines functions to get, add, edit, and delete data from a Google Sheet. It opens the specified sheet, then the doGet and doPost functions check the action parameter to call the appropriate data handling function. The Tambah function adds a new row to the sheet with the received data if the ID does not already exist. The Edit and Hapus functions search the sheet for a matching ID, then update or delete the corresponding row. Responses are returned upon completion of each action.

Uploaded by

r37system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Spreadsheet CRUD Operations

The document defines functions to get, add, edit, and delete data from a Google Sheet. It opens the specified sheet, then the doGet and doPost functions check the action parameter to call the appropriate data handling function. The Tambah function adds a new row to the sheet with the received data if the ID does not already exist. The Edit and Hapus functions search the sheet for a matching ID, then update or delete the corresponding row. Responses are returned upon completion of each action.

Uploaded by

r37system
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

var ss = SpreadsheetApp.

openByUrl("Your URL Spreadsheet");


var sheet = [Link]("Sheet1"); //name sheet

function doGet(e){
var action = [Link];

if(action == "tambah"){
return Tambah(e, sheet);
}

if(action == "edit"){
return Edit(e);
}

if(action == "hapus"){
return Hapus(e);
}
}

function doPost(e){
var action = [Link];

if(action == "tambah"){
return Tambah(e, sheet);
}

if(action == "edit"){
return Edit(e);
}

if(action == "hapus"){
return Hapus(e);
}
}

function Tambah(e, sheet){

var id = [Link];
var nama_barang = [Link];
var stok = [Link];

var flag=1;
var lr= [Link]();
for(var i=1;i<=lr;i++){
var id1 = [Link](i, 1).getValue(); // Ashton: column index changed from
2 to 1
if(id1==id){
flag=0;
var result= "ID Sudah ada";
break; // Ashton: break the loop if id is found, this will save some time if
your list is huge
} }
[Link](flag);
//add new row with recieved parameter from client
if(flag==1){
var rowData = [Link]([id,nama_barang,stok]);
var result="Berhasil Input";
}
return
[Link](result).setMimeType([Link]);

return [Link]([Link] + "(" + result +


")").setMimeType([Link]);
}

function Edit(e){
var id = [Link];
var values = [Link](2,1,[Link](),3).getValues();

for(var i = 0; i<[Link]; i++){


if(values[i][0]==id){
i=i+2;

var nama_barang = [Link];


var stok = [Link];

[Link](i,2).setValue(nama_barang);
[Link](i,3).setValue(stok);

return [Link]("Berhasil merubah


data!").setMimeType([Link]);
break;

}
}
return [Link]("ID tidak
ditemukan!").setMimeType([Link]. TEXT);
}

function Hapus(e){
var id = [Link];
var values = [Link](2,1,[Link](),3).getValues();

for(var i = 0; i<[Link]; i++){


if(values[i][0]==id){
i=i+2;

[Link](i);

return [Link]("Berhasil menghapus


data!").setMimeType([Link]);
break;

}
}
return [Link]("ID tidak
ditemukan!").setMimeType([Link]. TEXT);
}

You might also like