Calling getUserByID() works in global scope but not in application scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 10:35 AM
Hello.
I have a business rule (BR) which has a custom script which gets information about a user other than the user I am currently logged in as, just like the following:
var ourUser = gs.getUser();
gs.print(ourUser.getFirstName()); //should print out the first name of the user you are currently logged in as
ourUser = ourUser.getUserByID('abel.tuter'); //fetched a different user --> Exception thrown here when in APPLICATION scope
gs. Âprint(ourUser. ÂgetFirstName()); //this should be the first name of the user you fetched above
This script was working fine when the BR has a GLOBAL scope. But the same script fails when it calls ourUser.getUserByID() in another BR which has an APPLICATION scope. The error is: TypeError: undefined is not a function
Thoughts anybody?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 11:40 AM
Hi Pat,
I am able to reproduce this error you mentioned with the below script for scoped application.
var ourUser = gs.getUser();
gs.print(ourUser.getFirstName());
However the below script works fine.
ourUser = ourUser.getUserByID('abel.tuter');
gs.print(ourUser.getFirstName());
Can you please check the same and confirm so that I can pass this to our platform team.
Also please go through the below links for more info.
Scoped GlideSystem API Reference - ServiceNow Wiki
Scoped GlideUser API Reference - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 12:02 PM
Hi Pradeep. I'm confused with what you posted: You said you were able to reproduce this error but then you say "However the below script works fine". Did you mean to say the script does not work fine for you?
Is the problem maybe that a scoped application cannot retrieve user info because it would be a security risk? Maybe I need to open up the permissions on the sys.user table perhaps?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2015 11:30 PM
Hi Pat,
Sorry for the confusion here. I mean the below script doesn't work for scoped application. Can you confirm if you see the same behavior.
var ourUser = gs.getUser();
gs.print(ourUser.getFirstName());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 06:32 AM
Hi Pradeep.
Yes the following script does not work for scoped application:
var ourUser = gs.getUser();
gs.print(ourUser.getFirstName()); --> Exception thrown here for scoped application
Also the following script does not work for scoped application:
ourUser = ourUser.getUserByID('abel.tuter');
gs.print(ourUser.getFirstName()); --> Exception thrown here for scoped application
The following error is thrown in both cases:
TypeError: undefined is not a function