作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
域中的每个用户都会启动一个简单的脚本,我们为休假权利而运行,但我们希望欢迎消息为“Hi First Name”,但该脚本似乎无法获取 getGivenName()
来自getActiveUser()
对于标准用户。
有办法吗?
最佳答案
正如评论和 Documentation 中所述,UserManager 服务只能由域管理员访问。
这是一个替代方案。域用户可能在自己的联系人中拥有自己,那么尽最大努力在其中找到自己怎么样?
/**
* Get current user's name, by accessing their contacts.
*
* @returns {String} First name (GivenName) if available,
* else FullName, or login ID (userName)
* if record not found in contacts.
*/
function getOwnName(){
var email = Session.getEffectiveUser().getEmail();
var self = ContactsApp.getContact(email);
// If user has themselves in their contacts, return their name
if (self) {
// Prefer given name, if that's available
var name = self.getGivenName();
// But we will settle for the full name
if (!name) name = self.getFullName();
return name;
}
// If they don't have themselves in Contacts, return the bald userName.
else {
var userName = Session.getEffectiveUser().getUsername();
return userName;
}
}
关于google-apps-script - 如何获取 getActiveUser() 的 getGivenName(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15016628/
域中的每个用户都会启动一个简单的脚本,我们为休假权利而运行,但我们希望欢迎消息为“Hi First Name”,但该脚本似乎无法获取 getGivenName()来自getActiveUser()对于
我是一名优秀的程序员,十分优秀!