Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Save database of Invoices in another sheet

29 views
Skip to first unread message

Raul Bencosme

unread,
Apr 20, 2025, 8:12:49 AMApr 20
to Google Apps Script Community
I am tring to copy and paste a values of a invoice un another sheet but i can only get one value i need to select each value one by one and then paste in the another Database sheet and when i save another invoice it save under the old line and etc. i am using this code


function GuardarDatosVenta_By_OE(){

  var Fecha = SpreadsheetApp.getActive().getSheetByName("FACTURA").getRange("D6").getValues();
 var NFC = SpreadsheetApp.getActive().getSheetByName("FACTURA").getRange("D4").getValues();
  var Nombre = SpreadsheetApp.getActive().getSheetByName("FACTURA").getRange("B10").getValues();
  var BD = SpreadsheetApp.getActive().getSheetByName("Facturas");

  BD.appendRow(Fecha[0],NFC[0],Nombre[0]);
//BD.appendRow(NFC[0]);
//BD.appendRow(Nombre[0]);
  Browser.msgBox("Dato guardado");

  BD.activate();

Michael O'Shaughnessy

unread,
Apr 21, 2025, 8:06:49 PMApr 21
to google-apps-sc...@googlegroups.com
Hello Raul!  I applaud you jumping into coding this solution!  I am not sure how you are using it HOWEVER let's discuss some issues.

First, you are using ".getRange("B10").getValues() and when you use the plural (Values) you will get a 2d array of one value.  So let's say you have a "Newton" in B10, when you run your code the variable Nombre will be equal to this: [["Newton"]].  Notice the double bracket?

If you are getting a single cell value the you should use the singular version, such as ".getRange("B10").getValue()" Now Nombre will look like this: "Newton".

Now, when you go to append the data to a row the argument must be a 1d array of values.  This can be done by adding brackets.  For example: BD.appendRow([Fecha[0],NFC[0],Nombre[0]]);

If you change things and use getValue() then it can be written like this: BD.appendRow([Fecha, NFC, Nombre])

Give it a shot and let us know if it works.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/ae08cade-73a7-4a6b-b550-c79a97ed6e8bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages