I’m expecting to get the job title of the user via using google app script, but I’m getting the log print as follows
JavaScript
x
2
1
[20-11-17 12:31:35:307 IST] [{title=Manager, department=Marketing, primary=true, customType=}]
2
The below is my code
JavaScript
1
6
1
function getUserDirectory(){
2
var user = Session.getActiveUser().getEmail();
3
var employee = AdminDirectory.Users.get(user).organizations;
4
Logger.log(employee);
5
}
6
What I’m trying to do is get only the title of the employee. I’ve tried adding [1] or [2] or [3] after the .orgainizations object but it doesn’t work.
What would be the right code to get my answer?
Advertisement
Answer
employee
is a array of objects and contains only 1 object with index 0
. So, use
JavaScript
1
2
1
employee[0].title
2