Ezra Epriputra

unread,
Apr 14, 2019, 11:42:02 AM4/14/19
to MIT App Inventor Forum
Hi everybody thanks always answer my question....

I have a script that i try modified from this link...


then i try modified that link like this

var sheet = ss.getSheetByName("Sheet1");

function doGet(e){
  var action  = e.parameter.action;
  
  if(action == "pass")
    return Password(e);
   
  
}


function doPost(e){
  var action  = e.parameter.action;
  
  if(action == "pass")
    return Password(e);
   
  
}

function Password(e){
  var id = e.parameter.id;
  var values = sheet.getRange(2,1,sheet.getLastRow(),1).getValues();
  
  for(var i = 0 ; i<values.length ; i++){
    if(values[i][0] == id){
      i=i+2;
      var paswrd = e.parameter.Password;
      sheet.getRange(i,3).setValue(paswrd);
      return ContentService.createTextOutput("Thank You ! Password Update").setMimeType(ContentService.MimeType.TEXT);
    }
  }
  return ContentService.createTextOutput("Id Not Found").setMimeType(ContentService.MimeType.TEXT);
}
 and deploy as web and get try to browser the link like this


but my spreadsheet become like this 

SSworng.png


i need to make update password in my app inventor with SS as database...
thanks before for your response...

TimAI2

unread,
Apr 14, 2019, 12:16:19 PM4/14/19
to MIT App Inventor Forum
This not really an AI2 question !

You need some curly braces { } around your if statements.

if (action == "pass") {
    return Password(e);
  }

You are not sending a parameter for the new Password.

Should read:


I presume you have another script to test the id/user/pass

Ezra Epriputra

unread,
Apr 14, 2019, 12:28:48 PM4/14/19
to MIT App Inventor Forum
Yeah actually its no AI2 questions because my whole AI2 project using spreadsheet as database...

I try all step by step...

Thanks for your fast response...its work...
Im very glad this forum help me alot...

Ezra Epriputra

unread,
Apr 17, 2019, 12:11:24 AM4/17/19
to MIT App Inventor Forum
help me again please...
i make delete Hapus function but cant get right...


var sheet = ss.getSheetByName("Sheet1");

function doGet(e){
  var action  = e.parameter.action;
  var hapus = e.parameter.hapus;
  
  if(action == "ubah"){
    return Rubah(e);
  }
  
  if(action == "hapus"){
    return Hapus(e);
  }
}


function doPost(e){
  var action  = e.parameter.action;
  
  if(action == "ubah")
    return Rubah(e);
  
    if(action == "hapus"){
    return Hapus(e);
  }
}

function Rubah(e){
  var Kont = e.parameter.kontainer;
  var values = sheet.getRange(2,1,sheet.getLastRow(),2).getValues();
  
  for(var i = 0 ; i<values.length ; i++){
    if(values[i][1] == Kont){
      i=i+2;
      var paswrd = e.parameter.Password;
      var ket = e.parameter.Keterangan;
      sheet.getRange(i,4).setValue(paswrd);
      sheet.getRange(i,5).setValue(ket);
      return ContentService.createTextOutput("Thank You ! Updated").setMimeType(ContentService.MimeType.TEXT);
    }
  }
  return ContentService.createTextOutput("Id Not Found").setMimeType(ContentService.MimeType.TEXT);
}

function Hapus(e){
  var Kont = e.parameter.kontainer;
  var values = sheet.getRange(2,1,sheet.getLastRow(),2).getValues();

  for(var i = 0 ; i<values.length ; i++){
    if(values[i][1] == Kont){
    sheet.deleteRow(i);
    return ContentService.createTextOutput("Berhasil Hapus").setMimeType(ContentService.MimeType.TEXT);
    }
  }
}

need this script for my Ai2 App inventor

TimAI2

unread,
Apr 17, 2019, 4:34:12 AM4/17/19
to MIT App Inventor Forum
Which part is not working (always helps if you tell us that!)

Please show an example browser url for each function and also open up sharing on your sheet so i can see what is happening

for "rubah" I would expect the end to be (at least):

?action=ubah&kontainer=Kont&Password=mypass&Keterangan=myket

for "hapus":

?action=hapus&kontainer=Kont

Not sure why you have the i=i+2 in your Rubah function ?
Reply all
Reply to author
Forward
0 new messages