I want to get the email address of the person who accessed it in GAS, get the matching cell from Spreadsheet, replace the email address with a name, and send it to chat.

Asked 1 years ago, Updated 1 years ago, 466 views

I would like to obtain the data of the cell to the right of the cell matching the email address in the program shown below and substitute the text below.

var payload={
   "text"—text
   }

What I've tried so far:

  • admin directory
  • Try attaching a sample code online

Anyway, I'm a beginner and I don't even use JavaScript, so I don't know at all.(My specialty is Python)
I think there are some difficulties in understanding my poor writing, but I appreciate your cooperation.

As Is:

// Log the person who accessed the document and send it to chat
function readent() {
/// retrieve the logs of the person who accessed the document
  varurl='https://chat.googleapis.com/*****************************************************';
 vartext=Session.getActiveUser().getEmail();
 var payload = {
   "text"—text
   }
 varjson=JSON.stringify(payload);
 var options = {
   "method": "POST",
   "contentType": 'application/json; charset=utf-8',
   "payload": json
 }

 /// link a list to an e-mail address from Spreadsheet
 var response=UrlFetchApp.fetch(url, options);
 Logger.log(response);
  varsheetId="**************************";
  varsheet=SpreadsheetApp.openById(sheetId);
  range=sheet.getDataRange();
  var values = range.getValues();

  varmap = {}
  for (vari=1;i<values.length;i++){
    map[values[i][1]]=values[i][0];
    Logger.log(map)
  }
  return map;
}  

google-apps-script google-spreadsheet

2022-12-03 08:17

1 Answers

The following code replaces text with relevant information:

function info_search(){
  varsearch=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().createTextFinder(Session.getActiveUser().getEmail()) .findAll();/list format
  vartext=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange('B'+search[0].getA1Notation().substring(1).getValue();
}

Below is the explanation (though roughly)

.getActiveSpreadsheet()//Get a currently valid spreadsheet
.getActiveSheet()//Get the currently valid sheet
.createTextFinder(Session.getActiveUser().getEmail()/*Get email address*/)// Specify what you want to search for (like a filter)
.findAll()// Search

.getRange('B'+i.getA1Notation().substring(1)/*Assume that column A contains the email address and column B contains the information, get the cell with "i.getA1Notation()" and transform the form of "A?" in ".substring(1)" to "?" and "B+..." to "B?"Change accordingly to the actual sheet.*/)/* Specify cells*/
.getValue()// Get the contents of the cell

Reference URL
How do I find a spreadsheet in Google Apps Script


2022-12-03 08:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.