gs.getUser().getDomainID() not working in scoped application scripts

aditya_snow1
Tera Contributor

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

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

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


View solution in original post

13 REPLIES 13

alexlwm
Giga Expert

Hi Aditya,



Please try global.gs.getUser().getDomainID()



Alex


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


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


Thanks Alex. Please let me know if you find anything.



Aditya