The CreatorCon Call for Content is officially open! Get started here.

How to make tab visible using showTabByID

Markell
Tera Guru

Hi Guys

I am simply trying to write a code that shows a tab based on a field value.

I chose to use a UI Policy as I thought it may be easier and wrote the following code as the 'Execute if true':

function onCondition() {
g_tabs2Sections.showTabByID('section_tab.sys_id');
g_form.addInfoMessage("Message");

}

The message shows up fine but the tab does not change to show the tab referenced in the code.

For clarity, I want to use showTabByID because I feel its more robust than using tab index as the index can change and is likely to in this form.

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hey @Markell ,

Have you explored on below:

FUJI UPDATE: In the Fuji release, ServiceNow finally fixes this with a standard g_form call! You can now hide form sections using their name like this…

 

g_form.setSectionDisplay('schedule', false);

The first parameter is simply the name of your section, which should be completely lower-case. Sections including spaces should use an underscore in place of the first space with the rest of the spaces removed. For example, a form section with a label of ‘Schedule and Planning’ would require a parameter of ‘schedule_andplanning’. The second parameter is a true/false boolean that indicates whether the form section should be visible or not.

Ref link:

https://servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

View solution in original post

5 REPLIES 5

Maik Skoddow
Tera Patron
Tera Patron

Hi

please have a look on the following great article: https://community.servicenow.com/community?id=community_blog&sys_id=01ccee25dbd0dbc01dcaf3231f9619dc

Kind regards
Maik

I saw this article its what made me try to use showTabByID but just not able to get it to work unfortunately

Aman Kumar S
Kilo Patron

Hey @Markell ,

Have you explored on below:

FUJI UPDATE: In the Fuji release, ServiceNow finally fixes this with a standard g_form call! You can now hide form sections using their name like this…

 

g_form.setSectionDisplay('schedule', false);

The first parameter is simply the name of your section, which should be completely lower-case. Sections including spaces should use an underscore in place of the first space with the rest of the spaces removed. For example, a form section with a label of ‘Schedule and Planning’ would require a parameter of ‘schedule_andplanning’. The second parameter is a true/false boolean that indicates whether the form section should be visible or not.

Ref link:

https://servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

On this article the code 

'Change Active Tab Selection for Form Sections'

 

did what I wanted. Id have preferred to use sys_id but beggars can't be choosers lol 

 

Thanks