getCompanyID is not acquiring companyID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2021 08:06 AM
Hi,
I am trying to acquire login user's CompanyID by using this code:
javascript: gs.getUser().getCompanyID();
However, when I try this code on Scripts Background, it returns blank.
Result:
One of the post said that there might be some ACL restriction from core_company table which prevent it to be read.
Anybody know how to solve this issue??
Thanks in advance!
Best regards,
Leo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2021 08:25 AM
Hi
did you execute above code at script console as an admin?
If so, did you check the admin's user record that there is a company set?
If not, please provide more details and screenshots as it is not really clear what your concern is!
Kind regards
Maik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2021 09:08 AM
Adding to what
Frank

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2021 10:14 AM
Hi there,
The syntax itself is correct.
How are you testing this? Can you share your way of testing?
For example, I also just reproduced. Initially, also my test gave a blanc result. Checked my user record, no company... filled the company, retest: still blanc.
Logged off, logged in again, retest (exact same code): success.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:13 AM
I'm having the same problem with my instance. gs.getUser().getCompanyID() isn't returning a value.
It seems logging out and logging in resolves the problem. After logging out and then in, gs.getUser().getCompanyID() was able to return a proper value.
Following script, however, is able to get the value without doing a logout/login so it may be better.
var gr = new GlideRecord('sys_user');
if (gr.get(gs.getUserID())) {
gs.info(gr.company);
}