- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 02:57 AM
Hi Guys,
I am trying to retrieve the current session's Domain using a server side scoped application script. Using the 'gs.getUser().getDomainID() ' function gives the following error-
'Cannot find function getDomainID in object com.glide.script.fencing.ScopedUser'
Is there any other way to retrieve the current domain using a scoped application script without explicitly calling a globally scoped script?
Any help would be highly appreciated.
Thanks,
Aditya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2017 11:28 AM
Hi Aditya,
The session/user getDomainID() methods are not exposed to scope currently. As a workaround, I'd suggest creating a Script Include with a method you can call that will create a domain-separated record and just read the domain off of it. Like this:
var DomainInfo = Class.create();
DomainInfo.prototype = {
initialize: function() {
},
getCurrentDomain : function() {
var throwAwayRecord = new GlideRecord("sys_user");
throwAwayRecord.newRecord();
return throwAwayRecord.getValue("sys_domain");
},
type: 'DomainInfo'
};
Then when you want to get the domain, you call your Script Include:
var currentDomain = new DomainInfo().getCurrentDomain();
This assumes that the sys_user table is domain-separated. I'd suggest using a domain-separated table which doesn't have Number Maintenance or other auto-incrementing stuff, since we are deliberately initializing a full record, but never saving it.
Thanks,
Cory Seering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 03:23 AM
Hi Aditya,
Please try global.gs.getUser().getDomainID()
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 05:39 AM
Hi Alex,
Thanks for your reply.
I have already tried global.gs.getUser().getDomainID(), this doesnt work as well.
I have also tried GlideDomainSupport.getCurrentDomainValueOrGlobal(), gs.getSession().getCurrentDomainID().
All of these work perfectly in globally scoped scripts, but none of them work in scoped application scripts, even with global qualifiers.
Don't know if its a bug, or service-now has restricted the access to these functions in scoped scripts.
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 07:20 AM
Hi Aditya,
I searched for 40 minutes now, can't find a thing about this. I'll let you know when an idea pops up.
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 11:07 PM
Thanks Alex. Please let me know if you find anything.
Aditya