producao santadica
producao santadica

Reputation: 15

AppendRow() Limited Rows

How can I save data from a form only up to line 15? (as in the picture)?

function addNovaLinha(dadosLinha) {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getSheetByName("resultados");
  const dataAtual = new Date();
  var limite = ss.getLastRow();

  ws.appendRow([dadosLinha.item, dadosLinha.qtd, dataAtual]);

  return true;  
}

view image of sheet

Upvotes: 0

Views: 63

Answers (2)

producao santadica
producao santadica

Reputation: 15

thankful for help. I managed to solve. with the response from

Upvotes: 0

NightEye
NightEye

Reputation: 11184

You need to add a condition that checks if the last row has already reached 15.

function addNovaLinha(dadosLinha) {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const ws = ss.getSheetByName("resultados");
  const dataAtual = new Date();
  var limite = ss.getLastRow();

  // append row and return true ONLY IF last row is less than 15 
  if(limite < 15) {
    ws.appendRow([dadosLinha.item, dadosLinha.qtd, dataAtual]);
    return true;
  }
}

Upvotes: 1

Related Questions