- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:02 AM
Hi
How do you toggle the tab to active but not hide based on the dropdown selection?
if the Status = planning
then toggle the tab to Planning tab but do not hide the other tabs.
Client Script code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
/*var sections = g_form.getSectionNames();
alert(sections);*/
if (g_form.getValue('status') == 'planning') {
g_form.setSectionDisplay('planning', true);
} else {
g_form.setSectionDisplay('planning', false);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 11:42 AM - edited 01-24-2023 11:43 AM
Thanks for the help, I found my own solution.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue("status") == "planning") {
g_tabs2Sections.setActive(2);
} else if (g_form.getValue("status") == "fieldwork" || g_form.getValue("status") == "manager_review") {
g_tabs2Sections.setActive(3);
} else if (g_form.getValue("status") == "finalizing" || g_form.getValue("status") == "director_review") {
g_tabs2Sections.setActive(4);
} else if (g_form.getValue("status") == "vp_review") {
g_tabs2Sections.setActive(5);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:08 AM
Hi @Spaceballs ,
Please check the link below:
https://servicenowguru.com/scripting/client-scripts-scripting/changing-active-tab-selection-servicen...
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:17 AM
Hi @Spaceballs ,
We did something similar using below script
var tabName = 'new, test, done';
var myTabs = $('tabs2_section').select('span[class="tab_header"]');
var answer = 0;
for (i = 0; i < myTabs.length; i++) {
var inner = myTabs[i].innerHTML.replace(/&nbsp;/g, ' ');
if(inner.indexOf(tabName) > -1) {
answer = i;
break;
}
}
//Display the selected section
g_tabs2Sections.setActive(answer);
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:54 AM
Hi @Basheer ,
Thanks for the code but I'm getting error: onChange script error: TypeError: $ is not a function function () { [native code] }
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
/*var sections = g_form.getSectionNames();
alert(sections);*/
var tabName = 'milestones, assigned_to, planning,';
var myTabs = $('planning').select('span[class="tab_header"]');
var answer = 0;
for (i = 0; i < myTabs.length; i++) {
var inner = myTabs[i].innerHTML.replace(/\x26nbsp;/g, ' ');
if (inner.indexOf(tabName) > -1) {
answer = i;
break;
}
}
//Display the selected section
g_tabs2Sections.setActive(2);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 11:42 AM - edited 01-24-2023 11:43 AM
Thanks for the help, I found my own solution.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue("status") == "planning") {
g_tabs2Sections.setActive(2);
} else if (g_form.getValue("status") == "fieldwork" || g_form.getValue("status") == "manager_review") {
g_tabs2Sections.setActive(3);
} else if (g_form.getValue("status") == "finalizing" || g_form.getValue("status") == "director_review") {
g_tabs2Sections.setActive(4);
} else if (g_form.getValue("status") == "vp_review") {
g_tabs2Sections.setActive(5);
}
}