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

Dear Mohamed,



Thank you!



However, I have come across a complication that may or may not be how it is supposed to work but is not how it is desired to work.   We are on Fuji Patch 13 Hot Fix 1.   I have a Client Script to hide a Section by Name:



function hideSectionByName(name) {


  var sections = g_form.getSections();


  for(var i = 0; i < sections.length; i++) {


  var txtProps = '';


  if (sections[i].textContent.lastIndexOf(name, 0) === 0) {


  try {


  //sections[i].style.display = 'none';


  sections[i].remove();


  }


  catch (err) {


  alert('Error hiding Sensitive Information Tab:   ' + err.message);


  }


  }   // if (sections[i].textContent.lastIndexOf(name, 0) === 0)


  }


}



While this Client Script successfully hides the Section, it leaves the Tab visible which is less than ideal.   As is implied with the commented out line, I have also tried setting the CSS Display value with no change in result.   Might you or anyone else have found a solution to this?



Thank you in advance.



Respectfully,


Robert


Hi Similar to this


Instead of display = "none" can i do readOnly = "true". I mean i tried but its not working.



Basically Is there a way to make Form Section read only.. My requirement is to make form section readonly based on some condition


Thanks Mohamed Faizeal.



In the code statement below, 4 can be replaced with n, where n can take on the following values: 0,1,2,3,4. The value n depicts the index of the form section you would like to perform the operation on:



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



Code:


function onLoad() {


var sections = g_form.getSections();


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


}


jlt
Kilo Contributor

What about the tabs?


The Above code is applied for tab i.e., section. I have 5 tabs and i want to hide the 5th tab so wrote this code in onload   and done it.