I want to automatically assign the username of the executor in GAS

Asked 1 years ago, Updated 1 years ago, 398 views

I would like you to automatically enter the person who executed this script in the vertxt='; section. What should I do from here?

We have removed some of the var url parts for confidentiality.

function onOpen2(){
  varurl='https://chat.googleapis.com';
  var text = 'Automatically insert viewer's name';
  var payload = {
    "text"—text
    }
  varjson=JSON.stringify(payload); 
  var options = {
    "method": "POST",
    "contentType": 'application/json; charset=utf-8',
    "payload": json
  }

  var response=UrlFetchApp.fetch(url, options);
  Logger.log(response);

}

google-apps-script

2022-12-05 05:15

1 Answers

The email address (login ID) of the current session user (the user who opened the GAS) can be obtained from Session.getActiveUser().getEmail().

Documentation: Session.getActiveUser()

However, only getEmail() methods are available for users who can obtain only the email address (login ID).If you also want to get a user's name, you will need to get the user information from that email address using Directory API.


2022-12-05 06:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.