Home > Software engineering >  I execute my function, and it returns a function () { [native code] }
I execute my function, and it returns a function () { [native code] }

Time:12-11

I execute my function, and it returns a function () { [native code] }

function Simpan() {
  var Sheet = SpreadsheetApp.getActiveSpreadsheet();
  var shtinput = Sheet.getSheetByName('Input Form');
  var shtdb = Sheet.getSheetByName('Database');

  var nomorinput = shtinput.getRange('D3').getValue();
  var namaitem = shtinput.getRange('D5').getValue();
  var jumlahitem = shtinput.getRange('D7').getValue;
  var tgl = shtinput.getRange('D9').getValue;
  
  var baris = shtdb.getRange('E1').getValue();
  baris  = 1;
  var rangeisi = shtdb.getRange('A'   baris   ':D'  baris);
  rangeisi.setValues([[nomorinput,namaitem,jumlahitem,tgl]]);
  
}

It should show the input from the sheet

CodePudding user response:

I see where is the problem, check the comments below:

function Simpan() {
  var Sheet = SpreadsheetApp.getActiveSpreadsheet();
  var shtinput = Sheet.getSheetByName('Input Form');
  var shtdb = Sheet.getSheetByName('Database');

  var nomorinput = shtinput.getRange('D3').getValue();
  var namaitem = shtinput.getRange('D5').getValue();
  var jumlahitem = shtinput.getRange('D7').getValue; // << you cannot call .getValue without following ()
  var tgl = shtinput.getRange('D9').getValue; // << you cannot call .getValue without following ()
  
  var baris = shtdb.getRange('E1').getValue();
  baris  = 1;
  var rangeisi = shtdb.getRange('A'   baris   ':D'  baris);
  rangeisi.setValues([[nomorinput,namaitem,jumlahitem,tgl]]);
  
}

As I mentioned earlier,

when you call function (or method) in javascript, if you call them without (), it returns the definition of that function (or method) instead of executing them.

to make this code work as your expectation, you have to change it into:

function Simpan() {
  var Sheet = SpreadsheetApp.getActiveSpreadsheet();
  var shtinput = Sheet.getSheetByName('Input Form');
  var shtdb = Sheet.getSheetByName('Database');

  var nomorinput = shtinput.getRange('D3').getValue();
  var namaitem = shtinput.getRange('D5').getValue();
  var jumlahitem = shtinput.getRange('D7').getValue();
  var tgl = shtinput.getRange('D9').getValue();
  
  var baris = shtdb.getRange('E1').getValue();
  baris  = 1;
  var rangeisi = shtdb.getRange('A'   baris   ':D'  baris);
  rangeisi.setValues([[nomorinput,namaitem,jumlahitem,tgl]]);
  
}

  • Related