0% found this document useful (0 votes)
63 views1 page

Script Latihan Spreadsheet

This document defines functions for adding data to a Google Sheet. It opens a specific spreadsheet and sheet. The doGet and doPost functions check for an "tambah" action and call the Tambah function if found. Tambah gets parameter values from the request, checks if the ID already exists, and appends a new row with the values if not. It returns a success or error message.

Uploaded by

sfdsfdxfxfdx
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)
63 views1 page

Script Latihan Spreadsheet

This document defines functions for adding data to a Google Sheet. It opens a specific spreadsheet and sheet. The doGet and doPost functions check for an "tambah" action and call the Tambah function if found. Tambah gets parameter values from the request, checks if the ID already exists, and appends a new row with the values if not. It returns a success or error message.

Uploaded by

sfdsfdxfxfdx
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
You are on page 1/ 1

var ss =

SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1TyIcK0EffkkQtRg2m
ibOeW_8qAajn7Vca-uInK3X0Vk/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");

function doGet(e){
var action = e.parameter.action;

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

function doPost(e){
var action = e.parameter.action;

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

function Tambah(e, sheet){

var id = e.parameter.iddata;
var nama = e.parameter.namaorng;
var nohp = e.parameter.nope;
var alamat = e.parameter.alamatorng;
var keterangan = e.parameter.keterangan;

var flag=1;
var lr= sheet.getLastRow();
for(var i=1;i<=lr;i++){
var id1 = sheet.getRange(i, 1).getValue(); // Ashton: column index changed from
3 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
} }
Logger.log(flag);
//add new row with recieved parameter from client
if(flag==1){
var d= new Date ();
var currentTime = d.toLocaleString ();
var rowData = sheet.appendRow([currentTime,id,nama,nohp,alamat,keterangan]);
var result="Berhasil Input";
}

return
ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.TEXT);

return ContentService.createTextOutput(e.parameter.callback + "(" + result +


")").setMimeType(ContentService.MimeType.JAVASCRIPT);
}

You might also like