In a Google Workspace for Education environment I want to work with a customSchema in the user's profile in order to automate some administrative tasks.
Suppose I have made a customSchema called "housing" in the admin backend. Within "housing" I have made an item "rooms", which contains the value "4".
I succeeded already in retrieving all the user's profile information. The output (Logger.log...
) indeed contains the customSchema.
Retrieving a fullName or a givenName from the profile is no problem either.
This is my working code so far.
function myTryout() {
// code needs import of service = Admin SDK
var myEmailAdress = Session.getActiveUser().getEmail();
// INFO = https://stackoverflow.com/questions/48912906/retrieve-custom-attribute-from-user-profile-in-google-api-scripts-google-admin
var iAm = AdminDirectory.Users.get(myEmailAdress);
var myName = iAm.name.fullName;
Logger.log("USER'S FULL NAME = " + myName);
allMyData = AdminDirectory.Users.get(myEmailAdress,{projection: 'full'});
Logger.log("ALL USER'S DATA = " + allMyData);
}
However, accessing the data from customSchemas doesn't seem as straightforward.
So what is the code to extract the value for "rooms" from a user's data? And what is the code to write (or overwrite) this value from a user's data?
Logger.log("ALL USER'S DATA = " + allMyData)
shows me all available data in the user's profile:
{"thumbnailPhotoEtag":"\"3mhkESrZKxFccxpwig0yxvrUnxZYMxZUQujDNbVwMy4/jqzjWbJaD1m-N5bWVFSSTQ59Rr8\"","primaryEmail":"a_teacher@babotaniek.be","id":"112697199011841056502","emails":[{"address":"a_teacher@babotaniek.be","primary":true},{"address":"a_teacher@babotaniek.be.test-google-a.com"}],"orgUnitPath":"/","customerId":"C04agxt6k","agreedToTerms":true,"isEnrolledIn2Sv":false,"isMailboxSetup":true,"name":{"givenName":"a","familyName":"teacher","fullName":"a teacher"},"kind":"admin#directory#user","isDelegatedAdmin":false,"isAdmin":false,"etag":"\"3mhkESrZKxFccxpwig0yxvrUnxZYMxZUQujDNbVwMy4/oVtc4zE6rVvNCi4C8ycs-g15wqw\"","archived":false,"creationTime":"2018-09-06T20:19:55.000Z","ipWhitelisted":false,"changePasswordAtNextLogin":false,"isEnforcedIn2Sv":false,"lastLoginTime":"2022-02-15T11:27:05.000Z","nonEditableAliases":["a_teacher@babotaniek.be.test-google-a.com"],"customSchemas":{"babotaniek":{"aantal_km_met_de_fiets_heen_en_terug":6,"rijksregisternummer":"76798732544","stamboeknummer":"67867547567865","rekeningnummer":"FR798757654877658"},"housing":{"rooms":6,"sinks":7}},"languages":[{"preference":"preferred","languageCode":"nl"}],"thumbnailPhotoUrl":"https://www.google.com/s2/photos/private/AIbEiAIAAABECPa96Lmo5-CasAEiC3ZjYXJkX3Bob3RvKig4YjcxMDRhNzBiNmZkNDRiM2E3MmZjNzk3OTAzNGY0NTkyMTM2MmVhMAEsJu9fD0gMXnysdJsU_77BAHnQgQ","includeInGlobalAddressList":true,"suspended":false}
Note that the customSchemas and the values therein are listed.
If you're so kind to answer my question, please keep in mind that I'm rather new to coding. I didn't understand the few things I found on the web, so please give an answer suitable for dummies.