I have read and re-read the docs (here) and here and related. Is there some other documentation that will help me get a better understanding of what type of permissions require what type of formatting, etc?

The puzzle I'm trying to solve is this: when someone edits a cell, I'd like the cell colors to be formatted based on the user who edited it.

It's easy to write a code that works just for myself; however, I keep running into problems with permissions in getting it to work for another person.

Here's where I get confused. I'll explain my understanding, and I hope you can either correct me or point me to a document with more info. There seem to be 3 ways to make an event occur when a cell is edited: an Edit Event, a simple onEdit trigger, and an installable onEdit trigger.

To create a simple onEdit trigger, you create a new function named onEdit(). To capture an event, you put a string in the parentheses, eg onEdit(e). And then to access info stored on edit, you type something like var range = e.source.getActiveRange(). Simple event triggers have restricted security and cannot get the name of a user/activeUser, so I can't use them to solve my problem.

To create an installable onEdit trigger that captures an event, you create a new function, eg myFunction(e). Then you get into script editor, click "resources", select your function from the dropdown, hit "from spreadsheet," and then onEdit. In this case, to access information about the event, you type something like var range = e.range.

This method is supposed to give more advanced permissions so that I should be able to go "variable user = e.user" and then "ss.toast(user)" to see the name of the user. However, when anyone besides myself does this, the toast is blank. Also, with this, I know the script "runs as the user who installed the script" but does that mean I can't access the identity of the person who triggered the script?

To create an Edit Event, you... well... is this the same thing as creating a trigger? I guess I'm totally lost on this one.

So what happens if I cross my wires-- for example, I name something myFunction(e) and make an installable onEdit trigger, but then instead of typing range = e.range I type range = e.source.getActiveRange? It seems to work the same for just me, but then have I crossed up permissions so that it will act like a simple event instead of an installable one?

The docs say:

"They may not be able to determine which user triggered the event being handled. For clock tick events, this is not important, but in a Spreadsheet edit event, the user changing the Spreadsheet would not necessarily be identifiable."

So... not necessarily? When would it work and when wouldn't it? Is it possible in my case? How do I find out (besides my current, failing method of trial-and-error?).

有帮助吗?

解决方案

The documentation around this is a little confusing, and we should work to clarify it. If you use a simple trigger and the effective user, you should be able to get what you want.

function onEdit() {
  SpreadsheetApp.getActiveRange()
      .setComment('Last Editor: ' + Session.getEffectiveUser().getEmail());
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top