How to sent an alert when somone open the Spreadsheet using Google Script -


situation:

i have spreadsheet 15 worksheets , 20 users logging in , modifying it.

i have following script should send email user email adress open spreadsheet.

script function needed:

  1. send email when user open spreadsheet.

problem:

session.geteffectiveuser() getting the email owner of script , not getting user email.

the session.geteffectiveuser() since july23 should re-autorization user. perform following note re-approve script other user script , google account

test case:

this script have trigger when open spreadhseet.

    function loginshift(){       var ss = spreadsheetapp.getactivespreadsheet();          mailapp.sendemail("xxxxxx@gmail.com", "login shift" , "login username: " + session.geteffectiveuser());       } 
  1. when open spreadsheet owner of script, same sent me email email address open spreadsheet.
  2. when open spreadsheet different user not owner of script, script run , send email using owner mailbox , not mailbox of user open spreadsheet.

i have other script session.geteffectiveuser() onedit , working fine. don't know why script not getting email address geteffectiveuser.

there features described in documentation:

understanding triggers

...

installable triggers

...

  • when spreadsheet or form editor opened. (note trigger not activate when user opens form respond, rather when editor opens form modify it.) unlike simple trigger onopen, installable trigger can act user installed trigger.

...

the behavior mention in question expected according documentation.

update

if have simple trigger (oninstall, onopen, onedit) follows:

function onopen() {   logger.log('getactiveuser(): ' + session.getactiveuser());   logger.log('geteffectiveuser(): ' + session.geteffectiveuser()); } 

when executed owner of script, result follows:

getactiveuser(): owner_of_the_script geteffectiveuser(): owner_of_the_script 

when executed another user (not owner of script), result follows:

getactiveuser():  geteffectiveuser(): user_activates_the_trigger 

important: read limitations of simple triggers in documentation.

if have installable trigger follows , add function event onopen of spreadsheet:

function myonopen() {   logger.log('getactiveuser(): ' + session.getactiveuser());   logger.log('geteffectiveuser(): ' + session.geteffectiveuser()); } 

when executed owner of script, result follows:

getactiveuser(): owner_of_the_script geteffectiveuser(): owner_of_the_script 

when executed another user (not owner of script), result follows:

getactiveuser():  geteffectiveuser(): owner_of_the_script 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)