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

Hide Tab/Section in client script

Mohamed Faizel
Giga Expert

Hi,

How to hide the form sections and tab using client script?

I   was trying the below client script with the reference of http://www.servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/

It was not working, hope it was working fine in Eureka   and we are in fuji now and it's not working in fuji, i tested in demo also, the below script not working

function onLoad() {

  //Hide the section

var section = $$('span[tab_caption_raw="Questions"]')[0].select('span[id*=section.]')[0];

section.hide();

  alert(section);

//Hide the tab

$$('.tab_caption_text').each(function(caption) {

      if(caption.innerHTML == 'Questions'){

              caption.up('.tab_header').hide();

      }

});

}

Could any one please help on this?

Thanks.

1 ACCEPTED SOLUTION

Mohamed Faizel
Giga Expert

I just tried the below script in Fuji, i can hide the section.


function onLoad() {  


var sections = g_form.getSections();  


sections[4].style.display = 'none';


}


Thanks.


View solution in original post

17 REPLIES 17

jesusemelendezm
Mega Guru

I created an on change CS but I can't get it to work, I need to hide three sections based on check box on the top of change form. Can anyone share some hints for fuji release?


Try the above script in onchange and let us know


All good resolved.


Hi there, i want to be able to only show a section based on the choice value of another field.(see below)



So if Leaver is selected show the Leavers tab.


Screen Shot 2015-12-19 at 08.54.00.png


I've had a crack at an onload client script but am not getting it right. As you can see i have no scripting knowledge. Any help/pointers on this please?



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


if (newValue == "Leaver")


{var sections = g_form.getSections();


sections[5].style.display = 'true';


}


}


davidgilmore
Tera Contributor

There is an OOTB g_form method for this, where you can use the name of the section, rather than DOM and hoping the order of the sections never changes:


g_form.setSectionDisplay(sectionName, display)


Parameters:
sectionName - name of the section to be shown or hidden. The section name is lower case with an underscore replacing the first space in the name, and with the remaining spaces being removed, for example "Section Four is Here" becomes "section_fourishere". Other non-alphanumeric characters, such as ampersand (&), are removed. Section names can be found by using the getSectionNames method.
display - set true to show, false to hide.
Returns:
Boolean - true if successful.