Function getCompanyID is not allowed in scope sn_sc in sandbox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 12:11 AM
I've created a variable set to use on my Request items
I want the variable set to provide logged in users manager, company and department, so I added javascript:gs.getUser().getManagerName() / .getCompanyID() / .getDepartmentID() as default value.
When checking out the order, I get an error; saying Function getCompanyID is not allowed in scope sn_sc in sandbox.
But it looks like every thing is working as intended, the information that I wanted is provided in the requested item, and the request is submitted.
But I don't like having an error message showing up every time somebody order something, and I have no clue on where to start fixing this.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 12:17 AM
Hey,
Can you clarify this part:
" scope sn_sc in sandbox."
According to the Product Documentation, getCompanyID() is a valid function of GlideUser in an Application Scope.
The only way I know of to run code in scope is in Sandbox Mode via Background Scripts.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 01:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 12:00 AM
You can also check if a "Dynamic Filter Option"/sys_filter_option calls gs.getUser().getCompanyID(). Deactivating it may resolve the message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 12:53 AM
Hi,
getManagerName() is not a function which is available. Possibly it is breaking at that point.
getManagerID - is not allowed in scope
getCompanyID - is allowed in scope
In order to get logged in user's manager's company etc you can use script in the default value
javascript: var company; var rec = new GlideRecord('sys_user'); rec.get(gs.getUserID()); var manager = new GlideRecord('sys_user'); manager.get(rec.manager); company = manager.company; company;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader