How to show tabs based on Condition ?

snow_neh
Kilo Contributor

I am working on Incident form and I am stuck at one point. I have one field named No. of screens which is of Choice type. I have added 0, 1, 2, 3, 4, and 5 as the values to the drop down and I have created five new form sections named Screen 1, Screen 2, Screen 3, Screen 4, and Screen 5 with their respective fields added to it.

Can anyone please guide me that how can I display no form section when 0 is selected from drop-down, Screen 1 form section when 1 is selected from the drop down. Screen 1, and Screen 2 tabs when 2 is selected. Screen 1, Screen 2, and Screen 3 as tabs when 3 is selected. Similar process should be followed for 4 and 5 screens selected.

4 REPLIES 4

Victor Ruiz
Tera Guru

snow_neh
Kilo Contributor

Thank you for your suggestion Victor.



I tried implementing the same, however, I am not getting the desired result. Here is the script that I am using. Can you please assist me with it.




function onCellEdit(sysIDs, table, oldValues, newValue, callback) {


  var saveAndClose = true;


//Type appropriate comment here, and begin script below



  var sections = g_form.getSections();


  //Type appropriate comment here, and begin script below


  var sec1= sections[7];


  var sec2= sections[8];


  var sec3 = sections[9];


  var sec4 = sections[10];


  var sec5 = sections[11];



  if(g_form.getValue('u_no_of_screen') == '1')


  {


  sec1.style.display = 'block' ;


  }



  if(g_form.getValue('u_no_of_screen') == '2')


  {


  sec2.style.display = 'block' ;


  }



  if(g_form.getValue('u_no_of_screen') == '3')


  {


  sec3.style.display = 'block' ;


  }



  if(g_form.getValue('u_no_of_screen') == '4')


  {


  sec4.style.display = 'block' ;


  }



  if(g_form.getValue('u_no_of_screen') == '5')


  {


  sec5.style.display = 'block' ;


  }


  else


  {


  sec1.style.display = 'none' ;


  sec2.style.display = 'none' ;


  sec3.style.display = 'none' ;


  sec4.style.display = 'none' ;


  sec5.style.display = 'none' ;


  }





callback(saveAndClose);


}




Thanks !!


What version of ServiceNow are you using?


Tabs can be displayed by built in API in Fuji.



Also, I'm not sure if onCellEdit is the correct event.


í�ou may wish to try onChange event



14.7 setSectionDisplay

boolean 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". Section names can be found by using the getSectionNames method.
display - set true to show, false to hide.
Returns:
Boolean - true if successful.



GlideForm (g form) - ServiceNow Wiki

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Also can you write the code in an onChange or onLoad client script and try.



If you are on fuji then its way better to go with the setSectionDisplay() mention by Paul Morris.