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

146
Visualizações
Loop ID through cells in Google Apps Script

Good Day! I would like the Purchase Order ID repeated upon submission of a form in an earlier sheet. My current code however repeats this throughout the length of data range. Can I get help in modifying the code or loop/if statement below? Thank you in advance.

function exportPO() {
var myGooglSheet = SpreadsheetApp.getActive();
var shSource = myGooglSheet.getSheetByName("Source");
var shDatabase = myGooglSheet.getSheetByName("Database");
var lastRow = shDatabase.getLastRow()

var ProductValues = shSource.getRange("B5:C14").getValues();
shDatabase.getRange(lastRow+1,2,ProductValues.length,2).setValues(ProductValues);

var PO = shSource.getRange("C1").getValues();
var lines = 0;

var ProductRow = ProductValues.length;
for(var i=0; i<ProductRow; i++)
  if (ProductValues!=''){
  lines= lines+1;
  shDatabase.getRange(lastRow+lines,1).setValues(PO);
  shDatabase.getRange(lastRow+lines,4).setValue(new Date()).setNumberFormat('yyyy-mm- 
  dd h:mm'); //Submitted On
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In relation to

var ProductValues = shSource.getRange("B5:C14").getValues();

The above line assigns a Array of Arrays to ProductValues

In relation to

ProductValues!=''

The above expression always will return false. You might change this to ProductValues[i].every(value => value != '') to compare all the values in a row to an empty string, if all are not a empty string, this will return true, otherwise false, or change the original expression to something like ProductValues[i][0]!='' to compare on value of each row to an empty string, the first index corresponds to the row, the second to the column.

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