Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!