I was able to get the user name from the below code, is there a way to get the user's designation (or mobile number or work location?)
function getUser() {
var user = Session.getActiveUser().getEmail();
var employee = AdminDirectory.Users.get(user).name.fullName;
Logger.log('User data:\n%s', JSON.stringify(employee, null, 2));
console.log(employee);
}
Using the same AdminDirectory.Users.get()
method you can obtain phone numbers and work locations by specifying the fields you want on the return.
The method has a large response body which can be seen in the documentation.
You can see in this resource the two pieces of data you are looking for:
phones[]
:list
A list of the user's phone numbers. The maximum allowed data size for this field is 1Kb.
locations[]
:list
The user's locations. The maximum allowed data size for this field is 10Kb.
You can then filter out the data you desire with sub categories, for example phones[].type
or locations[].area
.
In order to retrieve, for example, phone numbers, you can filter the requeest in the same way:
var employee = AdminDirectory.Users.get(user);
var phones = employee.phones
var loc = employee.locations
Logger.log('User data:');
Logger.log(phones);
Logger.log(loc);
Will yield a log with the following format:
[20-11-02 12:12:28:243 CET] User data:
[20-11-02 12:12:28:247 CET] [{type=home, value=123456789}, {value=987654321, type=mobile}]
[20-11-02 12:12:28:250 CET] [{floorSection=Upper, floorName=Floor 12, type=desk, buildingId=5, area=cityView}]