App Script Code
App Script Code
App Script Code
var op = e.parameter.action;
var ss=SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/
1f5CbbSHduB_U6PTlXUt6Di9afoHMNb1ghKsS6rri4sI/edit#gid=0");
var sheet = ss.getSheetByName("Sheet1");
if(op=="insert")
return insert_value(e,sheet);
if(op=="update")
return update_value(e,sheet);
if(op=="delete")
return delete_value(e,sheet);
function insert_value(request,sheet){
var id = request.parameter.id;
var country = request.parameter.name;
var flag=1;
var lr= sheet.getLastRow();
for(var i=1;i<=lr;i++){
var id1 = sheet.getRange(i, 2).getValue();
if(id1==id){
flag=0;
var result="Id already exist..";
} }
//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,country]);
var result="Insertion successful";
}
result = JSON.stringify({
"result": result
});
return ContentService
.createTextOutput(request.parameter.callback + "(" + result + ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
function read_value(request,ss){
return output;
}
data.push(record);
}
return data;
}
//update function
function update_value(request,sheet){
result = JSON.stringify({
"result": result
});
return ContentService
.createTextOutput(request.parameter.callback + "(" + result + ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT);
function delete_value(request,sheet){
if(flag==0)
var result="id not found";
result = JSON.stringify({
"result": result
});
return ContentService
.createTextOutput(request.parameter.callback + "(" + result + ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT);