0
votes

I have the piece of code below. The functions "emailNaoAutorizado" and "emailAutorizado" are working well when i run each one alone. But, when i run each inside the function "onEdit" the functions doesn't work anymore.

Someone can help me?

function emailNaoAutorizado(){
  Logger.log("Email");  
  MailApp.sendEmail({
    to: "[email protected]",
    subject: "Resultado da sua solicitação de passagem em barreiras",
    body: "Você NÃO foi autorizado HOJE"
  })
};


function emailAutorizado(){
  Logger.log("Email");  
  MailApp.sendEmail({
    to: "[email protected]",
    subject: "Resultado da sua solicitação de passagem em barreiras",
    body: "Você foi autorizado HOJE"
  })
};


function onEdit(e) {  
  var range = e.range;
  if (range.getRow()  >= 1 && range.getColumn() == 17 ){
    var value = range.getValue();

    if (value == 'Autorizado') {
      range.setNote('Email de autorização enviado');
      emailAutorizado();

    } else if (value == 'Não Autorizado') {
      range.setNote('Email de NÂO Autorização enviado');
      emailNaoAutorizado();

    } else {
      range.setNote('Defini célula para AUTORIZADO ou NÂO AUTORIZADO');
    }
  }
}
1
Could you provide execution logs? Did you install the onEdit trigger ? - Aerials

1 Answers

0
votes

Could you try async/await like this

    async function onEdit(e) {
        var range = e.range;
        if (range.getRow()  >= 1 && range.getColumn() == 17 ){
            var value = range.getValue();

            if (value == 'Autorizado') {
                range.setNote('Email de autorização enviado');
                await emailAutorizado();

            } else if (value == 'Não Autorizado') {
                range.setNote('Email de NÂO Autorização enviado');
                await emailNaoAutorizado();

            } else {
                range.setNote('Defini célula para AUTORIZADO ou NÂO AUTORIZADO');
            }
        }
    }