我正在与同事共享一张表,并希望他们在打开文件后输入他们的名字以便记录。我自然也没有运行任何脚本的问题。
打开文件后,脚本不会触发,但我可以找到错误日志,他们会说: 您无权在onOpen上调用inputBox(代码:12)。这是为什么?我能做些什么呢? 此外,存在相同错误消息但具有代码13和14的实例。
我还没有熟练掌握Apps脚本,但这是一个授权,保护问题吗?
function onOpen() {
//Log the user
var id, usrprops, logname;
id = Browser.inputBox('ID Check', 'Enter your identity (nickname) and press OK', Browser.Buttons.OK);
if (!id) { //if The user did not enter a name
id = Session.getActiveUser().getEmail(); //Get the logged users email address
id = id.slice(0,id.indexOf("@")); //Remove the domain part of email address
}
usrprops = PropertiesService.getUserProperties(); //Get User Properties
usrprops.setProperty('usrname', id); //Save the user name with a key name
return id;
}