Changing the Active form tab

Cirrus
Kilo Sage

Hi, my question comes in two parts:

We have three form tabs on our incident form - notes, related records and resolution details, with notes the default active tab. Firstly, I created a basic on load client script to change the active tab from notes to related records, which worked fine (g_tabs2Sections.setActive(1);). However, when I made the client script inactive and reloaded the incident form, the related records tab remained the active tab. Does ServiceNow change system properties when this script is used??

Now my main issue. The resolution tab only appears when the incident state changes to resolved. The user has to fill in mandatory fields before they can save (so its not possible to save the state to resolved and then complete the resolution details - they have to change the state, fill out the fields and then save all together). I am trying to script it so that when they change the state to resolved, the Resolution Details tab appears as the active tab (at present they have to click on it to change the active tab from notes to resolution). I tried the following onLoad client script, but it doesnt change the default notes tab

function onLoad() {
var gr = new GlideRecord('incident');
gr.addQuery('state','resolved');
gr.query();
if (gr.next()) {
g_tabs2Sections.setActive(2); }
}

Note sure if this is my script (probably!) or totally the wrong approach. Can anyone advise please

 

 

1 ACCEPTED SOLUTION

Cirrus
Kilo Sage

The following on change script has solved the issue:

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

if (g_form.getValue("state") == "6"){
g_tabs2Sections.setActive(2);
}

}

View solution in original post

3 REPLIES 3

Ct111
Giga Sage

Hi ,

 

You want to make Close Notes section active but that behaviour already exist  for  onCHange  of state to Resolved so I want to know 

y are u implementing the same .

 

But, still if you have some reasons for it then follow the below link it will give you correct idea about how to script the same.

 

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

 

 

Mark my ANSWER as CORRECT and HELPFUL if it helped.

Thanks Creatiethinker,

The issue is that when the user sets to Resolved, they have to make an additional mouse click to fill out the Resolution details. It would be a better user experience if it opened that tab directly. I had been looking at the servicenowguru page to try and come up with a solution, but to no avail

find_real_file.png

Cirrus
Kilo Sage

The following on change script has solved the issue:

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

if (g_form.getValue("state") == "6"){
g_tabs2Sections.setActive(2);
}

}