How we can dynamically change current domain based on caller's domain on a new incident?

gee
Tera Guru

Hi Team,

In a domain separated instance, how we can dynamically change current domain based on caller's domain on a new incident?

There are issues when creating a new incident   by an agent who belongs to multiple domains, relating to reference data such as priority, impact, urgency etc. Each domain may have different choice list for reference data. These reference data will be selected based on the agent's current domain and not based on caller's domain.

I think to resolve this issue, it is to select the right domain based on the caller for new incident creation.

Is there any sample script or any suggestion to implement this solution?

Your valuable suggestions and helps are most appreciated.

Thanks & Regards,

Gee

7 REPLIES 7

Kalaiarasan Pus
Giga Sage

gs.getUser().getDomainID();



Getting a User Object - ServiceNow Wiki


Hi Kalai,


Many thanks for your reply.



I am trying to use Client Script for changing the domain. Unfortunately gs.getUser command in not callable in Client Scripts. Is there any alternative solution available?



Client Script: 'On change of caller field on incident form, check and change the domain of the logged in user'



Thanks & Regards,


Gee


Add the line in a script include and call it using glideajax


raprohaska
Kilo Guru

This is not a perfect solution by any means and I'm early in the process. We have a similar need. The catch is that you want all your company/domain specific items like View and Choice lists to reload based on the domain change. You also want the user to realize their domain has changed so when they navigate away from the form, they know the context of views and such will be limited OR, as I want to do, have the user rerouted back to their default domain once the form is submitted.




In my early efforts, I'm adding a client script (on change of company) that uses the same code that runs when you change the domain from the domain picker. After changing the session's domain, then I reload the screen. The main issue with this part is that any other information that has been entered will be removed and they will have to click the "Leave Page" button since it will register the dirty read. In this example I'm hard coding the domain id but you would use g_form to read the company's domain field.




function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


    changeDomain('c90f91924a362312001bdefae0f35d68');


}


function changeDomain(target_domain) {


  //var o = this.select.options[this.select.selectedIndex];


  var ga = new GlideAjax('UIPage');


  ga.addParam('sysparm_name','changeChoice');


  ga.addParam('sysparm_function_select',"Domain");


  ga.addParam('sysparm_value',target_domain);


  ga.getXML(changeDomainResponse);




}




function       changeDomainResponse(response) {


  reloadWindow(window);


}