Issues with authorizations - sheet app script

1,123 views
Skip to first unread message

Eneko Rodríguez Larrinaga

unread,
Mar 17, 2021, 2:18:36 PM3/17/21
to Google Apps Script Community
hi!!


An attempt is made from a sheet to send an email to an address when the user changes a data on that sheet. When I run it in development it works, but running the sheet and changing the value doesn't work for me. It gives me an authorization error.

The error:

The code:

function onEdit(e){
  // Trigger, cuando un valoor cambia
  //e es el rango modificado

  var celdaEnviar= e.range;

  var dato= celdaEnviar.getValue();
  SpreadsheetApp.getActiveSheet().getRange("A15").setValue(dato);
  if (dato == 'ENVIAR'){
    SpreadsheetApp.getActiveSheet().getRange("A14").setValue("Ok a enviar");
    EnviarEmail()
    
  }
    else {
      SpreadsheetApp.getActiveSheet().getRange("A14").setValue("No ok a enviar");
  }

}

function EnviarEmail() {
  
  var hoja = SpreadsheetApp.getActiveSheet();

  SpreadsheetApp.getActiveSheet().getRange("A14").setValue("Hello world");

    //dar permiso
    

    // Recupero el email de la persona
    dato= hoja.getRange("A2").getValue()
    var email=dato;
    
    //Recupero el asunto para el email
    dato= hoja.getRange("B2").getValue()
    var asunto= dato;

    //Recupero el texto para el email
    dato= hoja.getRange("C2").getValue()
    var body=dato;

    GmailApp.sendEmail (email,asunto,body);


  }

Thnaks

Alan Wells

unread,
Mar 17, 2021, 2:50:38 PM3/17/21
to Google Apps Script Community
You will need to install a On Edit trigger in order to send an email I believe.
A simple onEdit function can set values in the Sheet, but it can't send an email without the user authorizing that permission.
Change the function name from onEdit to something else and then install an On Edit trigger.

Glen Wilson

unread,
Mar 17, 2021, 9:30:34 PM3/17/21
to Google Apps Script Community
Eneko,


There's Forever Free Version and  Discounted options for qualifying Education Organisation.

 Try Zenphi for free https://zenphi.com/signup/ _ or from the Google marketplace.

Eneko Rodríguez Larrinaga

unread,
Mar 19, 2021, 9:29:18 AM3/19/21
to google-apps-sc...@googlegroups.com
Thanks a lot!!!! It's running!!!!!

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/EHNjQOTWPd8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b9884867-0ffe-4a01-9d3e-97991bceb7a3n%40googlegroups.com.


--
Gogoratu!!! Musukua erabili, distantzi mantenu eta eskuak ondo garbitu !!! Lortuko dugu!!!

Recordad!!! Usar la mascarillas, mantened la distancia y limpiad bien las manos!!! Lo conseguiremos!!!

Eneko Rodriguez Larrinaga
Profesor y Responsable TIC 
    

Colegio Irlandesas Leioa Ikastetxea
94 480 70 51


Reply all
Reply to author
Forward
0 new messages