I have the following script for a simple pop up on opening the doc. Is there any way for this pop up to only show to the sheet owner and not all the other people the doc is shared with?
function onOpen() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var ui = SpreadsheetApp.getUi();
var Alert = ui.alert("TEXT HERE");
}
My use case for this, is a message visible to only me as the doc owner, which I don't want anybody else with sharing rights, ie clients, to see.
If my understanding is correct, how about this modification?
Modification points:
In this modification, it knows whether owner opened the Spreadsheet by retrieving the email of active user.
Session.getActiveUser().getEmail()
is owner's email.Session.getActiveUser().getEmail()
is retrieved.This is used.
Modified script:
Note:
Session.getActiveUser().getEmail()
is retrieved. So I think that this can be used. At that time,Session.getActiveUser().getEmail()
has owner's email.Reference:
If I misunderstood your question and this was not the result you want, I apologize.
Edit 1:
If all users install the trigger,
Session.getEffectiveUser().getEmail()
returns the value. So the value is required to be compared with that of the registered users. In this sample script, it supposes as follows.Sample script:
Edit 2:
When I tested this situation by 3 users just now, I noticed new issue.
At first, it supposes as follows.
onOpen_sample(){}
when the Spreadsheet is opened.ui.alert("TEXT HERE")
.In this situation, the following results are obtained.
onOpen_sample()
as a trigger of OnOpen.Session.getActiveUser().getEmail()
returns owner's email.Session.getEffectiveUser().getEmail()
returns owner's email.onOpen_sample()
as a trigger of OnOpen.Session.getActiveUser().getEmail()
returns no value.Session.getEffectiveUser().getEmail()
returns user1's email.Here,
onOpen_sample()
as a trigger of OnOpen.Session.getActiveUser().getEmail()
returns no value.Session.getEffectiveUser().getEmail()
returns user1's email.And furthermore,
onOpen_sample()
as a trigger of OnOpen.Session.getActiveUser().getEmail()
returns no value.Session.getEffectiveUser().getEmail()
returns owner's email.And also, when I installed the trigger of OnOpen several times, even if user1 and user2 install the trigger,
Session.getEffectiveUser().getEmail()
got to return only owner's email.By these, all users can run the script and open the dialog. I thought that your issue might be this. I think that this might be a bug. So I would like to report this to the issue tracker.
From this situation, in the current stage, it was found the following result.
I apologize that your issue was not resolved. If I found the workaround, I would like to report here.