Take mail ID by pressing a button in googlesheet

僤鯓⒐⒋嵵緔 提交于 2020-06-09 05:38:10

问题


Can someone suggest me a Google Script that will make a button that will get the mail ID of the person and put it into a specified Google sheet.


回答1:


This would be your script. Create a drawing like a button, via the little 3 dots you can assign it to a script, type: getEmail.

If the user is a gmail user it will append the value to the target sheet. If not then it opens a prompt where someone can enter the email.

function getEmail(){
  const ui = SpreadsheetApp.getUi();
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const targetSheet = ss.getSheetByName("targetsheet"); // change to desire
  const userMail = Session.getActiveUser().getEmail();

  if (userMail == null){
    targetSheet.appendRow(ui.prompt("Enter email").getResponseText());
  } else {
    targetSheet.appendRow([userMail]);
  }
}


来源:https://stackoverflow.com/questions/62222770/take-mail-id-by-pressing-a-button-in-googlesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!