B.Sabres15
B.Sabres15

Reputation: 57

Add user's secondary values (Employee Details) such as Title to Google Directory

I have wrote a script that successfully takes a Google Sheet full of User information and adds them to our Google Domain. I however can't seem to figure out how to add certain secondary values that are specific to our org. Some of the values are Employee ID, Title, (These are found under additional info when adding user) etc... I've been racking my brain all day trying different things, figured I'd ask here after searching for other posts that didn't quite answer the question

function AddUsers() {
 var ss=SpreadsheetApp.openByUrl('xxxxx');
 var sheet = ss.getSheets()[0];
 var data = sheet.getDataRange().getValues();
 for(var i = 1; i < data.length; i++) {
  var lastName = data[i][0];
  var firstName = data[i][1];
  var email = data[i][2];
  var password = data[i][3];
  var changePass = data[i][4];
  var orgPath = data[i][5];
  var groupEmail = data[i][6];
  var role = data[i][7];


var user = {
  "name" : {
    "givenName" : firstName,
    "familyName" : lastName
  }, 
  "primaryEmail": email,
  "password": password,
  "changePasswordAtNextLogin": changePass,
  "orgUnitPath": orgPath
};

AdminDirectory.Users.insert(user);

var group = {
  "email": email,
  "role":role,
};

AdminDirectory.Members.insert(group, groupEmail);

};
 };

Upvotes: 0

Views: 527

Answers (2)

B.Sabres15
B.Sabres15

Reputation: 57

I was able to resolve this issue by running a get query on a user, which Google returns all values with the proper titles, this gave me the format that I needed to add the values. It was a combination of organizations[] and exterenalID[].

Thanks for the help

Upvotes: 1

Luc Rubio
Luc Rubio

Reputation: 3

You could set them using Custom User Fields. See field customSchemas from the users resource.

Upvotes: 0

Related Questions