简体   繁体   中英

Google Script onEdit()

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: "tiagotozi@gmail.com",
    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: "tiagotozi@gmail.com",
    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');
    }
  }
}

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');
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM