0

I modified some google apps script but cant get right the delete (Hapus) function...please see the code below

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1XHbx_3PmTUHA8GB2mnrMR4j7TCi4X6uS5-1fVKi3_iI/edit#gid=0");
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();
  var lr= sheet.getLastRow();

  for(var i=1;i<=lr;i++){
    if(values[i][1] == Kont){
    sheet.deleteRow(i);
    return ContentService.createTextOutput("Berhasil Hapus").setMimeType(ContentService.MimeType.TEXT);
    }
  }
}
  • Welcome! We want you to succeed, but right now your question is not a great fit for StackExchange. SE is naturally not a coding service or debugging forum. As explained in How To Ask, (and likely why you didn't get a quick answer), please edit your question with what it should do, what it is doing incorrectly instead, what you've tried get it working, and what problems you've hit during your best efforts. – Joel Reid Apr 18 at 12:28
  • Web Apps StackExchange aside, if you're still working at the problem, your code looks like it could benefit from some of the Apps Script editors' built-in troubleshooting features. Start with their documentation for debugging and logging. – Joel Reid Apr 18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.