简体   繁体   中英

User/Email stamp with onEdit Google Sheets

What I want to do is to place the user's email who is clicking the checkbox to true in the cell directly next to the checkbox that they're clicking on. I've got the code so that I can place my own email there. I've even played with it to the point where it will remove the "@gmail.com," but I cannot get this to show for other users.

I had it, at one point, placing the current users emails in the box, but then it would quickly change to my own. However, I don't remember the state of the code as it was then, and haven't been able to replicate it.

I've tried everything suggested here.

I've also referenced this post here.

Here is my code:

function createTrigger(){
ScriptApp.newTrigger('myFunction').forSpreadsheet(SpreadsheetApp.openById('1Y0-bpAhGzPSS5DIPnoZH4OcY2b9IL8LhvBfc2is0zVU')).onEdit().create();
}
function myFunction(e) {
  var groupOneCheck = 3;
  var groupTwoCheck = 7;
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var checkCell = ss.getActiveCell();
  if (checkCell.getColumn() == groupOneCheck) {
    var dateTimeCell = checkCell.offset(0,2);
    var userCell = checkCell.offset(0,1);
    dateTimeCell.setValue(new Date());
    userCell.setValue([Session.getEffectiveUser().getEmail()]);
  }
  if (checkCell.getColumn() == groupTwoCheck) {
    var dateTimeCell = checkCell.offset(0,2);
    var userCell = checkCell.offset(0,1);
    dateTimeCell.setValue(new Date());
    userCell.setValue([Session.getEffectiveUser().getEmail()]);
  }  
}

I want to do the same thing for both of the if statements because they correspond to different columns.

Here is a link to the sheet that I am currently testing with.

如果我使用可安装的触发器,它对我有用,因为简单的触发器无法执行需要许可的功能。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM