- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 05:25 AM
Hi There,
I want to fetch the domain of current user in my script include.
i am using ...
var domain = gs.getUser().getDomainID();
gs.print('Domain ID is =='+domain )
This is giving me the domain of the user from domain picker. but i want to get the value which is there in the user table.
can i not get the value directly without gliderecording the user table?
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 06:08 AM
Just to inform gs.getUser().getRecord().getValue('fieldName') won't work in scoped application
It would work in global scope.
For Global Scope:
gs.info('Domain ID is ==' + gs.getUser().getRecord().getValue('sys_domain'));
For Custom scope
better you query sys_user table for that user and get the domain value
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
gs.info('Domain ID is ==' + user.sys_domain);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 05:33 AM
So the user record has a field domain, that contains a different value for domain?
You can use:
gs.getUser().getRecord().getValue('domain_field');
Replace domain_field with the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 05:37 AM
Hey Rj27,
Try this:
var domaine = gs.getUser().getDomainID();
var gruser = new GlideRecord('sys_user');
gruser.addQuery('sys_domain',domaine);
gruser.query();
while(gruser.next())
{
ans = gruser.getDisplayName();
return ans;
}
Mark it Correct or Helpful, if it works based on impact....!!!!
Best Regards,
Namrata.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 06:49 AM
Hi
as mentioned in my question,
var domaine = gs.getUser().getDomainID();
is giving me the value from domain picker but i want it from the user table.
I was looking for a solution where i do not have to gliderecord the user table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 05:57 AM
Hi,
If you want to show the domainId on form only then you can use the g_scratchpad, for that create an display BR and onload client script to display the domainId.
And if you want to use that value in script include for any operation then you have to use the GlideRecord.
Mark it correct and helpful.
Thanks
Bhagyashri Sorte.