Sukhwinder Rahal
Sukhwinder Rahal

Reputation: 3

Take mail ID by pressing a button in googlesheet

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.

Upvotes: 0

Views: 43

Answers (1)

RemcoE33
RemcoE33

Reputation: 1610

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

Upvotes: 1

Related Questions