Home > Blockchain >  How to add multiple data entry, If I clicked save only the top row is being recorded or save (automa
How to add multiple data entry, If I clicked save only the top row is being recorded or save (automa

Time:11-18

The problems: Let me start again: This file is for my Inventory tools. There are 3 sheets "IN" "OUT" "History". Others can only edit the "IN" and "OUT" sheets (if there are any inventories that came from the supplier they will put it on the "IN" sheet, if there are any inventories are used will be recorded on the "OUT" sheet). So the "history" sheet purpose its to record all data that being recorded by others on the "IN" and "OUT" sheets. I create a button to activate the script (move the data to the "History" sheet as well clear it. Hope I dont confuse you. What I mean "clear" is, data on the "IN" and "OUT" Sheets is clear but already recorded on the "History". The questions is, if the data on "IN" and "OUT" sheets is more than 1 columns, then I click the button. only the top column is being saved on the "History" sheet. Just like the photo I attached on the questions "Before click Save with script" and "Data is saved and Entry but only top row"

["IN" Sheet]

Click Button with this scripts

var blankRow=datasheet.getLastRow() 1;

datasheet.getRange(blankRow,1).setValue(shUserForm.getRange("A2:A500").getValue()); 
datasheet.getRange(blankRow,2).setValue(shUserForm.getRange("B2:B500").getValue()); 
datasheet.getRange(blankRow,3).setValue(shUserForm.getRange("C2:C500").getValue()); 
datasheet.getRange(blankRow,4).setValue(shUserForm.getRange("D2:D500").getValue()); 
datasheet.getRange(blankRow,5).setValue(shUserForm.getRange("E2:E500").getValue()); 
datasheet.getRange(blankRow,6).setValue(shUserForm.getRange("F2:F500").getValue());

["History" Sheet](The Desire Output is record the same just like the photo "IN" sheet

[THE SHEETS FOR TESTING]

FULL CODE: This is the full code

    function submitData1() {
  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var shUserForm= ss.getSheetByName("In-Inventory");
  var datasheet = ss.getSheetByName("DatabaseINVENTORY");
  var ui = SpreadsheetApp.getUi();
  var response = ui.alert("Submit", 'PASTIKAN SUDAH BENAR, YAKIN MAU SIMPAN DATA?',ui.ButtonSet.YES_NO);
  if (response == ui.Button.NO) 
  {return;
  } 
  var blankRow=datasheet.getLastRow() 1;
    datasheet.getRange(blankRow, 1).setValue(shUserForm.getRange("A2:A500").getValue()); 
    datasheet.getRange(blankRow, 2).setValue(shUserForm.getRange("B2:B500").getValue()); 
    datasheet.getRange(blankRow, 3).setValue(shUserForm.getRange("C2:C500").getValue()); 
    datasheet.getRange(blankRow, 4).setValue(shUserForm.getRange("D2:D500").getValue()); 
    datasheet.getRange(blankRow, 5).setValue(shUserForm.getRange("E2:E500").getValue()); 
    datasheet.getRange(blankRow, 6).setValue(shUserForm.getRange("F2:F500").getValue());
    ui.alert('REKAP INVENTORY TERSIMPAN');
    shUserForm.getRange("A2:A500").clearContent();
    shUserForm.getRange("C2:C500").clearContent();
    shUserForm.getRange("D2:D500").clearContent();
  return true ;
 }

CodePudding user response:

It's the same thing as this:

datasheet.getRange(datasheet.getLastRow()   1,1,1,6).setValues(shUserForm.getRange(2,1,1,6).getValues());

Everything is in the same row. Every piece of data in put into blankRow. There are no other rows.

If you really want to put all that data into one cell you can do it with something like this:

function myfunk() {
  const ss = SpreadsheetApp.getActive();
  const shUserForm = ss.getSheetByName('Sheet1');
  const datasheet = ss.getSheetByName('Sheet0');
  let s = '';
  shUserForm.getRange("A2:A10").getValues().forEach(r => {
    s  = r.join(',')   '\n';
  });
  datasheet.getRange(1, 1).setValue(s);
}

I did it with a smaller range and I assigned names to the sheets so that I could test it.

Why did you make this function?

function validateEntry1(){
  var ss= SpreadsheetApp.getActiveSpreadsheet(); 
  var shUserForm    = ss.getSheetByName("Master"); 
  var ui = SpreadsheetApp.getUi();
  return true;
}

I hope you don't think they're global because they're not

This is the function that I think you want:

function submitData1() {
  const ss = SpreadsheetApp.getActive();
  const insh = ss.getSheetByName("In-Inventory");
  const dsh = ss.getSheetByName("DatabaseINVENTORY");
  const ui = SpreadsheetApp.getUi();
  const response = ui.alert("Submit", 'PASTIKAN SUDAH BENAR, YAKIN MAU SIMPAN DATA?', ui.ButtonSet.YES_NO);
  if (response == ui.Button.NO) {
    return;//exit from this function
  }
  let vs = insh.getRange(2, 1, insh.getLastRow() - 1,insh.getLastColumn()).getValues();
  let d = 0;
  vs.forEach((r,i) => { 
    dsh.appendRow(r);
    insh.deleteRow(i   2 - d  )
  });
}

It's not working right now because your sheet is protected;

CodePudding user response:

The new code from Cooper with a tweak

function submitData2() {
      const ss = SpreadsheetApp.getActive();
      const insh = ss.getSheetByName("In-Inventory");
      const dsh = ss.getSheetByName("DatabaseINVENTORY");
      const ui = SpreadsheetApp.getUi();
      const response = ui.alert("Submit", 'PASTIKAN SUDAH BENAR, YAKIN MAU SIMPAN DATA?', ui.ButtonSet.YES_NO);
      if (response == ui.Button.NO) {
        return;//exit from this function
      }
      let vs = insh.getRange(2, 1, insh.getLastRow() - 1,insh.getLastColumn()).getValues();
      let d = 0;
      vs.forEach((r,i) => { 
        dsh.appendRow(r);
        insh.getRange("A2:A").clearContent();
      });
    }
  • Related