Set a new Focus on the different tabs of the incident according its state

Axel5
Kilo Expert

Hello,

I can't set a new Focus on the different tabs of the incident page (ex : When the status is resolved the Resolution Information tab is displayed)

I found the script that could apply it but impossible to make it work with a script client.. I don't know what I'm doing wrong.

https://servicenowguru.com/scripting/client-scripts-scripting/changing-active-tab-selection-servicen...

Someone would know how to do this and guide me?

 

Thank you !

1 ACCEPTED SOLUTION

Axel5
Kilo Expert

Super efficient !

 

Here the script at the end.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if(newValue == 6) {
        g_tabs2Sections.setActive(2); //Resolution Information tab
    }    
}

 

Thanks a lot for your help !

View solution in original post

5 REPLIES 5

Ian Mildon
Tera Guru

I am using a couple of similar scripts to set focus depending on record values. Here is an onChange Client Script as an example.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if(newValue == 3) {
		var close = g_tabs2Sections.findTabIndex('close_code'); //find id of tab with named field
		g_tabs2Sections.setActive(close); //set focus to the tab
	}	
}

Also, keep in mind that the "index" starts at 0 like in this example

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

	if (newValue == 1) { //if on hold awaiting Caller
		g_tabs2Sections.setActive(0); //set 'default' active
		setTimeout("var refocus = document.getElementById('incident.u_caller_contacted');refocus.focus();", 0);
	}
    if (newValue == 3) { //if on hold awaiting Problem
        g_tabs2Sections.setActive(1); //set Related Records active
        setTimeout("var refocus = document.getElementById('sys_display.incident.problem_id');refocus.focus();", 0);
    }
    if (newValue == 4) { //if on hold awaiting Vendor
        g_tabs2Sections.setActive(0); //set 'default' active
		setTimeout("var refocus = document.getElementById('incident.u_vendor_incident_number');refocus.focus();", 0);
    }
	if (newValue == 5) { //if on hold awaiting Change
        g_tabs2Sections.setActive(1); //set Related Records active
        setTimeout("var refocus = document.getElementById('sys_display.incident.rfc');refocus.focus();", 0);
    }
}

So you can go by the name or the index value.

Brian Lancaster
Tera Sage

This appears to be using dom manipulation. On the form for the client script add a filed called Isolate script and uncheck it.

Axel5
Kilo Expert

Thanks a lot for your answers. I unchecked the Isolate Script but I still have some work to do to configurate my script. I have a question for you Ian about the value 

(newValue == 3)

Is it a reference to the value of the choice list of the Field State ?

Those are the State values on our tables; 3 being a State of "On hold" for Incident.

State of Resolved would be 6 for Incident.