hy guys im learning google apps script to telegram bot,
i have write auto reply command and it success to reply, if i sent @02-02-2021 it will show all recorded data on that day, but on my code it just return only 1 row, i have trying anything but nothing work.
thanks for helping,
function searchDataByTanggalTransaksi(Tanggal){
var rangeNameTransaksi = "Transaksi!A2:O";
var rowsTransaksi = Sheets.Spreadsheets.Values.get(MYSSID, rangeNameTransaksi).values;
var panjangTransaksi = rowsTransaksi.length;
var Tanggal, Nama_Item, Divisi, Sat, Qty, Harga_Satuan, Debet, Kredit, Saldo, Peruntukan, Total = "";
var pesan ="";
for (var row = 0; row < panjangTransaksi; row++ ){
if ("@" + rowsTransaksi[row][1]==Tanggal){
Tanggal = "📅 Tanggal Transaksi : " + rowsTransaksi[row][1];
Nama_Item = rowsTransaksi[row][2];
Divisi = rowsTransaksi[row][3];
Sat = rowsTransaksi[row][4];
Qty = rowsTransaksi[row][5];
Harga_Satuan = rowsTransaksi[row][6];
Debet = rowsTransaksi[row][7];
Kredit = rowsTransaksi[row][8];
Saldo = rowsTransaksi[row][9];
Peruntukan = rowsTransaksi[row][12];
Total = "💸 Total Transaksi : " + rowsTransaksi[row][14] + ",-";
pesan += "<code>- " + Nama_Item + " |" + Qty + " " + Sat + " |" + Kredit + "</code>";
return pesan ;
}
}
return "Data tanggal tidak ditemukan";
}
function testgetRowsTransaksi(){
var tanggal = searchDataByTanggalTransaksi("@2");
var x = ""
}
4
Answers
i have found the work around, on above method i was use
return
, but when isendText
it reply all the rowsOne approach is to store found values in array, I assume that you want to return
pesan
right?So solution one of possible solutions is that every record that is found you store it into array, and then return whole array(if nothing found array length will be 0).
Here is there modified code:
Though I’m not pretty sure, what kind of data panjangTransaksi variable holds, if you just want the all matching items in a concatenated string, you could try like below
The program will never enter this
if ("@" + rowsTransaksi[row][1]==Tanggal)
asTanggal
is undefined.