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!