mercredi 4 juillet 2018

Google Apps Script, If else condition only giving else value

I have a google apps script code for telegram bot that use to giving information from the google spreadsheet. i use looping to find the data and give if condition and it run well, but when i include the else when the data not found on spread sheet, my script always giving else value even the data is exist on the spreadsheet. Here's my code:

function doPost(e) {
   // this is where telegram works
     var data = JSON.parse(e.postData.contents);
     var text = data.message.text;
     var id = data.message.chat.id;


  if (text == "/start"){
    var id = data.message.chat.id;
    var name = data.message.chat.first_name + " " + data.message.chat.last_name;
    var message = "Selamat datang " + name + " !" + "%0AUntuk mencari data pelanggan silahkan memasukkan /ODP_NAME.%0AContoh : /ODP-UBN-FAC/100";
  sendText(id,message); 
  }
  if(text.indexOf("/")>=0){ //jika dalam text terdapat "/" maka lanjutkan
    var odp = text.slice(1).split(" ")[0]; //menghapus karakter pertama dari 

    var rows = sheet.getRange(1,1,sheet.getLastRow(), sheet.getLastColumn()).getValues();

for(var i = 0 ; i < rows.length; i++){
  var name = rows[i][3];
  var sto  = rows[i][1];
  var pdname  = rows[i][2];
  var odpname  = rows[i][3];
  var odpindex  = rows[i][4];
  var latitudes  = rows[i][5];
  var longitudes  = rows[i][6];
  var isavai  = rows[i][7];
  var isblocking  = rows[i][8];
  var isothers  = rows[i][9];
  var isreserv  = rows[i][10];
  var isservice  = rows[i][11];
  var istotal  = rows[i][12];
  var gponname  = rows[i][13];
  var ipne  = rows[i][14];
  var modul  = rows[i][15];
  var port  = rows[i][16];
  var occ  = rows[i][17];
  var stat  = rows[i][18];
  var odc  = rows[i][19];
  var readinessont  = rows[i][20];
  var qrcode  = rows[i][25];
  var hasil = "BERIKUT DATA DARI ODP_NAME : " + odpname + "%0A %0A"  + "~ STO : " + sto + "%0A" + "~ PD_NAME : " + pdname + "%0A" + "~ ODP_INDEX : " + odpindex + "%0A" + "~ LATITUDE : " + latitudes + "%0A" + "~ LONGITUDE : " + longitudes + "%0A" + "~ IS_AVAI : " + isavai + "%0A" + "~ IS_BLOCKING : " + isblocking + "%0A" + "~ IS_OTHERS : " + isothers + "%0A" + "~ IS_RESERV : " + isreserv + "%0A" + "~ IS_TOTAL : " + istotal + "%0A" + "~ GPON NAME : "+ gponname + "%0A" + "~ IP NE : " + ipne + "%0A" + "~ MODUL : " + modul + "%0A" + "~ PORT : " + port + "%0A" + "~ OCC : " + occ + "%0A" + "~ STAT : " + stat + "%0A" + "~ Readiness ONT : " + readinessont + "%0A" + "~ QR CODE : " + qrcode;
  var long = (rows[i][3]);


  if(odp == long ){
      sendText(id,hasil);
      sendLocation(id,latitudes,longitudes);
      break;

    }else {
      sendText(id, "salah aja TEROZZZ!!!");
      break;
    }

  }

}else{
sendText(id, "Masukkan /ODP_NAME !%0AContoh : /ODP-UBN-FAC/100");
}

}     

i've been looking for 2 days and got nothing, hope there's some who could help. note: sorry for bad english

Aucun commentaire:

Enregistrer un commentaire