- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2018 05:23 PM
I am trying to write a catalog item client script displaying a message with the users domain.
I have tried many different script ideas over 10 hours but nothing I have tried works with Catalog client scripts.
How can I Call user domain in a catalog client script?
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2018 08:27 PM
i would suggest here, use display business rule and then you can call that variable in your onLoad() client script to get the value.
or if you want in onChange() client script , use glide ajax.
Sample Script:
Display Business rule:
var myUser = gs.getUser();
g_scratchpad.domain_id = myUser.getDomainID();
g_scratchpad.domain_display_value = myUser.getDomainDisplayValue();
OnLoad Client SCript:
alert(g_scratchpad.domain_id);
Another Approach: Using Glide Ajax.
Client Script: onChange()
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Script Include( make sure you mark "Client Callable" true.
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var myUser = gs.getUser();
var userDom = myUser.getDomainID(); // if you want id then you can pass "userDom" variable in return.
var userDomValue= myUser.getDomainDisplayValue();
return userDomValue ;
},
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2018 08:07 PM
you can do something like below. It's not recommended to do gliderecord query in client script.
Ref-https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
//This script gets the user's title
var gr = new GlideRecord('sys_user');
gr.get(g_user.userID);
var domain = gr.domain;
alert(domain);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2018 07:21 AM
If it is not recommended, then I cannot use it.
It is helpful to know it is not recommended; as I have already tried a few scripts using GlideRecord.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2018 08:27 PM
i would suggest here, use display business rule and then you can call that variable in your onLoad() client script to get the value.
or if you want in onChange() client script , use glide ajax.
Sample Script:
Display Business rule:
var myUser = gs.getUser();
g_scratchpad.domain_id = myUser.getDomainID();
g_scratchpad.domain_display_value = myUser.getDomainDisplayValue();
OnLoad Client SCript:
alert(g_scratchpad.domain_id);
Another Approach: Using Glide Ajax.
Client Script: onChange()
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Script Include( make sure you mark "Client Callable" true.
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var myUser = gs.getUser();
var userDom = myUser.getDomainID(); // if you want id then you can pass "userDom" variable in return.
var userDomValue= myUser.getDomainDisplayValue();
return userDomValue ;
},
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2018 07:41 AM
I started down this path with a Business Rule but ran into issues in my personal instance with scoped app.
I am trying this now in a dev client with global app now.
Thanks for your help and time,
I look forward to marking your answer as correct...