Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Google sheet Script issue

I'm trying to replicate a spreadsheet I saw online with modifications. The purpose of the spreadsheet is to document my Bull Put/Bear Call credit spreads. The plan is to have a dashboard sheet where I can enter the info and by clicking the add position button, it will transfer the info into the data sheet where all logs will be held. I will also be able to close positions from the dashboard page, but I have not even begun that script as of yet. The script I am putting together is.

function AddPosition() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dashboard = ss.getSheetByName("Dashboard");
  var data = ss.getSheetByName("Data");
  var expiration = dashboard.getRange(7, 3).getValue();
  var sym = dashboard.getRange(7, 4).getValue();
  var contracts = dashboard.getRange(7, 5).getValue();
  var type = dashboard.getRange(7, 6).getValue();
  var shortleg = dashboard.getRange(7, 7).getValue();
  var longleg = dashboard.getRange(7, 8).getValue();
  var pop = dashboard.getRange(7, 9).getValue();
  var credit = dashboard.getRange(7, 10).getValue();

if (expiration=="" ||
    sym=="" || 
    contracts=="" || 
    type=="" || 
    shortleg=="" || 
    longleg=="" || 
    pop=="" || 
    credit=="" || {
      **var ui = SpreadsheetApp.getUi(); // Same variations.**
      var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
      return;
}

  data.insertRowAfter(data.getLastRow());
  var lastRow = data.getLastRow();
  var now = new Date();
   data.getRange(lastRow, 1).setValue(now);
   data.getRange(lastRow, 2).setValue(sym);
   data.getRange(lastRow, 3).setValue(type);
   data.getRange(lastRow, 4).setValue(expiration);
   data.getRange(lastRow, 6).setValue(longleg);
   data.getRange(lastRow, 7).setValue(shortleg);
   data.getRange(lastRow, 9).setValue(contracts);
   data.getRange(lastRow, 10).setValue(credit);
   data.getRange(lastRow, 13).setValue(pop);

   data.getRange(lastRow-1, 33).copyTo(data.getRange(lastRow, 33));
   data.getRange(lastRow-1, 34).copyTo(data.getRange(lastRow, 34));
   data.getRange(lastRow-1, 35).copyTo(data.getRange(lastRow, 35));
   data.getRange(lastRow-1, 36).copyTo(data.getRange(lastRow, 36));
   data.getRange(lastRow-1, 37).copyTo(data.getRange(lastRow, 37));

  dashboard.getRange(7,2,1,11 ).clearContent();

}

On line 23 var ui = SpreadsheetApp.getUi(); // Same variations. I keep getting

SyntaxError:Unexpected identifier line:23 file: Code Gs

I don't know what I'm doing wrong.

Basically, I'm trying say if data is missing, an alert will fire stating "'Missing data','Please fill in missing values and try again.'"

Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I saw a few missing parenthesis within your if-else statement and also a few asterisks "*" on the declared var. Fixed it up and it executed properly on my end.

Try this:

if (expiration=="" ||
sym=="" || contracts=="" || type=="" || shortleg=="" || longleg=="" || pop=="" || credit=="") {
var ui = SpreadsheetApp.getUi(); //Same variations.
var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
return;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda