Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
App script array returns values if run from editor but returns undefined if run as trigger

Here is my google app script. The aim of the script is to look for duplicate values in column C and then highlight any duplicate value rows that it finds.

If i run the script from the editor window it runs just fine and highlights those duplicate rows but if i run it from a trigger either by form submit or time driven then the array returns undefined and so all rows are highlighted.

function findAndHighlightDupesInColumn() {
      var col=col||0;
      var ss=SpreadsheetApp.getActive();
      var sh=ss.getActiveSheet();
      var rg=sh.getRange("C2:C10");
      var vA=rg.getValues();
      console.log(vA)
      var uA=[];
      for(var i=1;i<vA.length;i++) {
        if(uA.indexOf(vA[i][col])==-1) {
          uA.push(vA[i][col]);
          console.log(uA)
        }else{
          sh.getRange(i+1,1,1,sh.getLastColumn()).setBackground('crimson');
        
        }
        
      }
      
    }

Here is the output of the console.log when run inside the editor window.

8:00:32 AM  Info    [ [ 1071184 ],
  [ 1069157 ],
  [ 1069567 ],
  [ 1098033 ],
  [ 1068959 ],
  [ 1090405 ],
  [ 1097753 ],
  [ '' ],
  [ '' ] ]


8:00:32 AM  Info    [ 1069157 ]
8:00:32 AM  Info    [ 1069157, 1069567 ]
8:00:32 AM  Info    [ 1069157, 1069567, 1098033 ]
8:00:32 AM  Info    [ 1069157, 1069567, 1098033, 1068959 ]
8:00:32 AM  Info    [ 1069157, 1069567, 1098033, 1068959, 1090405 ]
8:00:32 AM  Info    [ 1069157, 1069567, 1098033, 1068959, 1090405, 1097753 ]
8:00:32 AM  Info    [ 1069157, 1069567, 1098033, 1068959, 1090405, 1097753, '' ]

Here is the result when i run it from a time based or form submit trigger.

Dec 17, 2021, 7:38:38 AM    Debug   [ [ 'Job ID' ],
  [ 1071184 ],
  [ 1069157 ],
  [ 1069567 ],
  [ 1098033 ],
  [ 1068959 ],
  [ 1090405 ],
  [ 1097753 ],
  [ '' ],
  [ '' ] ]


Dec 17, 2021, 7:38:38 AM    Debug   [ undefined ]

Can anyone help? I have been banging my head against a wall with this issue.

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda