Call user domain in a catalog client script

Lon Landry2
Tera Contributor

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?

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

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 ; 
},
 });

 

 

View solution in original post

8 REPLIES 8

No luck with Business Rule and onLoad Client script...

can you share the screenshot?

what is coming in business rule log? i had mentioned two solutions, both did not work?

No success with business rule & client script.

I have no Glide Ajax experience; so I am reaching out on my team to find solution.

@Harshvardhan - The client side logic you have mentioned above, can we also use this in a UI script?

If so, can you please guide me as to how I would do that.

Thank you,

Ayshee Chattopadhyay