Update "Cost Center" for users in an OU

96 views
Skip to first unread message

James SEYMOUR

unread,
Nov 22, 2021, 10:30:40 PM11/22/21
to GAM for Google Workspace
Hi,

I am looking to update the "Cost Center" field for Staff & Students, to allow identifiction of each main group (Staff or Student).

I know I can run gam csv gsheet <User Email Address> <File ID> <Sheet Name> gam update user ~email organization costcenter "Staff or Student" against a Google Sheet, which is created daily showing all active users in each group.

But it would be easier to run against the OU, using, for example, gam update ou_and_children_ns /Staff organization costcenter "Staff". But this command gives an error. And gam ou_and_children_ns /Staff update organization costcenter "Staff" also gives an error.

So I just wanted to check if it was possible to update the "Cost Center" for users in an OU (and children) or not possible.

Cheers

James

Brian Kim

unread,
Nov 23, 2021, 6:18:59 AM11/23/21
to GAM for Google Workspace
Below should work, however, when updating organization, make sure you provide all the fields. If there were any other attributes, they would be lost when you set the cost centre.
gam update users ou_and_children_ns /Staff organization costcenter "Staff'"

James SEYMOUR

unread,
Nov 24, 2021, 11:06:03 PM11/24/21
to GAM for Google Workspace
Hi Brian,

Great, thanks for that. I am now getting a better idea of what is needed for updating these fields so I need to create a Google Sheet showing all the user's fields for all the users I need to update. However gam ou_and_children_ns /Path/To/OU print organizations todrive does not show all the fields, it only seems to show the fields that are currently filled in. 

Does anyone know what command is needed to show all these fields regardless of whether they have values or not. Then it will be possible to use this Google Sheet to update the Cost Center with a set value and re-populate the other fields with whatever they currently have.

Cheers

James

Ross Scroggs

unread,
Nov 26, 2021, 8:53:32 PM11/26/21
to google-ap...@googlegroups.com
James,

The API only returns the fields with values, you can't force it to return empty fields.
Experiment with formatjson quotechar "'" on output and json ~JSON on update.

Ross
Jerudong International School
https://www.jerudonginternationalschool.com
Follow us on:
http://www.facebook.com/jisbruneidarussalam http://www.twitter.com/jisbrunei http://www.instagram.com/jisbrunei https://www.youtube.com/user/JISBrunei https://www.flickr.com/photos/133960569@N03/albums

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/59287ab1-b361-4ff3-be30-8d34bc04fde1n%40googlegroups.com.

James SEYMOUR

unread,
Dec 1, 2021, 1:31:28 AM12/1/21
to google-ap...@googlegroups.com
Hi Ross,

Thanks for the info. I have not really looked into JSON files before, but I assume that each file needs to be edited to be able to update a user. So I don't think this will work for me as I am trying to automatically update a field based on the OU of a user.

The workaround I have (or will have) is to run these via cron'-
  1. Maintain a user with all the organization fields filled in. This ensures all the columns are created.
  2. gam ou_and_children_ns /StaffOU print organizations todrive tdfileid <File ID> tdtitle "<File Title>" tdsheet "Sheet1"
  3. gam csv gsheet <Owner Email Address> <File ID> 'Sheet1' gam update user ~primaryEmail organization costcenter "Staff" customtype "~organizations.0.customType" description "~organizations.0.description" title "~organizations.0.title" department "~organizations.0.department" primary
Manually the commands work OK. I just need to set up the Cron jobs.

Regards


James Seymour
Head of Systems and Communication
[t] +673.24.11.000  Ext 1203
[Time Zone] GMT +8 Hours


  I'm using Inbox When Ready to protect my focus.

Kim Nilsson

unread,
Dec 2, 2021, 6:08:10 PM12/2/21
to GAM for Google Workspace
Hah, I was just going to suggest #1. :-)
That's what I have.

Greg Matyola

unread,
Sep 3, 2025, 6:12:40 PM (2 days ago) Sep 3
to GAM for Google Workspace
Forgive the necro-post, but For GAM version 7+, you need to use "organization costcenter ~{field)" 


On Thursday, December 2, 2021 at 6:08:10 PM UTC-5 Kim Nilsson wrote:
Hah, I was just going to suggest #1. :-)
That's what I have.


Disclaimer:
This email, including any attachments, is intended only for the designated recipient(s) regarding the business of Hanover Township Public Schools. It may contain confidential or legally privileged information protected by law. Unauthorized review, use, disclosure, or distribution is prohibited. Email is not a secure form of communication and may be intercepted or altered. By communicating via email, you acknowledge these risks. The views expressed are those of the author and may not reflect the official position of Hanover Township Public Schools.

Ross Scroggs

unread,
Sep 3, 2025, 6:17:52 PM (2 days ago) Sep 3
to google-ap...@googlegroups.com
See: https://github.com/GAM-team/GAM/wiki/Users#admin-console-user-info

Yes, you'll need primary or notprimary to complete organization.

        organization [type domain_only|school|unknown|work] [customtype <String>]

                [name <String>] [title <String>] [department <String>]

                [symbol <String>] [costcenter <String>] [location <String>]

[description <String>] [domain <String>]

                [fulltimeequivalent <Integer>]

                notprimary|primary


Ross


----
Ross Scroggs



--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages