How domain sets on login

saprem_d
Giga Guru

Hi,

In a domain separated instance, domain of the user on login sets to the domain marked in user profile. I have requirement to set the domain updated in a custom field "Default Domain" to be set as the session domain of the user on login.

I need to know how the session domain gets set to user's domain (marked in his profile). Any help would be appreciated.

Bobby gfinney i have tagged you as you are best person i could think of to get an answer on this. Thanks in advance.

~Saprem

1 ACCEPTED SOLUTION

BobbyNow
ServiceNow Employee
ServiceNow Employee

You can accomplish this by creating a synchronous script action against the "session.established" event.


You can create a synchronous script action by inserting from the "Set Theme" script action, otherwise you have no access to the "Synchronous" field.


See below for an example script to get you started.


This will need to be globally scoped of course.



var default_domain = setDefaultDomain();




if (default_domain) {


      var d = new DomainSelect();


      d.changeDomain(default_domain);


}




function setDefaultDomain() {


      if (gs.hasRole("maint")) { //ignore maint


              return '';


      }




      //If this user has a default domain, set it.


      var usr = new GlideRecord('sys_user');


      if (usr.get(gs.getUserID())) {


              if (usr.u_default_domain) {


                      return usr.u_default_domain;


              }


      }


 


      return '';


}









View solution in original post

3 REPLIES 3

abhishekdash
ServiceNow Employee
ServiceNow Employee

Hello Saprem,



I think below discussion will help you achieve this:



How do I get the current domain in a client script



Also, I think you could use getDomainID() and getDomainDisplayValue() using User Object. Below document will help you in configuration:



http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0



I hope this information helps.



Thanks,


Abhishek



If this reply assisted you, please consider marking it Correct, Helpful, or Like it.


This helps other customers to learn from your thread.


BobbyNow
ServiceNow Employee
ServiceNow Employee

You can accomplish this by creating a synchronous script action against the "session.established" event.


You can create a synchronous script action by inserting from the "Set Theme" script action, otherwise you have no access to the "Synchronous" field.


See below for an example script to get you started.


This will need to be globally scoped of course.



var default_domain = setDefaultDomain();




if (default_domain) {


      var d = new DomainSelect();


      d.changeDomain(default_domain);


}




function setDefaultDomain() {


      if (gs.hasRole("maint")) { //ignore maint


              return '';


      }




      //If this user has a default domain, set it.


      var usr = new GlideRecord('sys_user');


      if (usr.get(gs.getUserID())) {


              if (usr.u_default_domain) {


                      return usr.u_default_domain;


              }


      }


 


      return '';


}









Hello Bobby,



Thanks for the quick revert.



I was also using the same logic but unfortunately i was trying to utilize login event.



This works very well by using synchronous session event. Thanks for the help. Really appreciated !!