问题描述
域中的每个用户都会启动一个我们为假期权利运行的简单脚本,但我们希望欢迎消息是Hi First Name,但脚本似乎无法从getActiveUser()中获取getGivenName()为标准用户。
有没有办法? 正如评论和中所述,UserManager服务只能由域管理员访问。
以下是另一种选择。域用户可能有他们自己的联系人,那么如何努力尝试在那里找到他们?
/ **
*通过访问他们的联系人来获取当前用户的名字。
*
* @returns {String}名字(GivenName)如果可用,
*其他FullName或登录ID(用户名)
*如果在联系人中找不到记录。
* /
函数getOwnName(){
var email = Session.getEffectiveUser()。getEmail();
var self = ContactsApp.getContact(email);
//如果用户有自己的联系人,则返回他们的名字
if(self){
//如果有可用的名称,则返回
var name = self.getGivenName();
//但是,如果(!name)name = self.getFullName(),我们将解决全名
的问题。
返回名称;
}
//如果他们在联系人中没有他们自己,则返回秃头用户名。
else {
var userName = Session.getEffectiveUser()。getUsername();
返回用户名;
}
}
Each user on the domain initiates a simple script we run for leave entitlements but we want the welcome message to be "Hi First Name," however the script doesn't seem to be able to fetch getGivenName() from getActiveUser() for a standard user.
Is there a way?
As noted in comments, and in Documentation, the UserManager Service is only accessible by Domain Administrators.
Here's an alternative. Domain Users may have themselves in their own contacts, so how about a best-effort attempt at finding themselves there?
/**
* 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;
}
}
这篇关于谷歌脚本如何getGivenName()的getActiveUser()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!