0

I am transmitting data from WordPress to google sheets and I made a script that generates unique code for each row, but it generates code only for data written manually and it does not react to data coming from WordPress.

ID_LENGTH = 5;

function generateUID () {
  var ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var rtn = '';
  for (var i = 0; i < ID_LENGTH; i++) {
    rtn += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));
  }
  return rtn;
}

function onEdit(e) { 
    
  const row = e.range.getRow();
  const col = e.range.getColumn();
  const as = e.source.getActiveSheet();
  
  if(col==3){
    as.getRange(row, 6).setValue(generateUID());
  }
}

I understand that the point is in the features of the onEdit function, is that right? How can this be fixed?

0 Answers0