Hide and display Form section based on the conditions.

anubhavr
Giga Expert

I have a requirement for 'Change Request' that 'Closure Information' Related tab should be visible only after 'Implement' state or in 'Cancelled' state. how to implement it?

1 ACCEPTED SOLUTION

anubhavr
Giga Expert

Hi All,



I got the solution.



I can be done using Client Script 'OnLoad'.



function onLoad() {


  var st=g_form.getValue('state');



  if(st=='-5'|| st=='-4'|| st=='-3'||st=='-2') {


  var sections = g_form.getSections();


  g_form.setSectionDisplay('closure_information', false);


}


  else {


  var sections = g_form.getSections();


  g_form.setSectionDisplay('closure_information', true);


}


}


View solution in original post

4 REPLIES 4

anurag92
Kilo Sage

you can write a UI policy with condition as State = Implement/Cancelled. Under UI action set Closure info field as visible and make the UI policy as 'Reverse if false', so that for other states it is invisible.


Abhinandan Pati
Giga Guru

Hi Anubhav,



You can use 'hideRelatedList()' & methods of 'g_tabs2Sections' in client script or UI Policy to hide related lists & sections. Refer below articles for more details



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#hideRelatedList


Demystifying form tabs



Thanks


Abhinandan


Gopinath Laksh1
Kilo Contributor

Hi Anubhav,



Just make an on change client script for change request table on change of State field with following code..



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



//checking whether the new value of the state if Implement or cancelled


if (newValue == "Implement" || newValue == "Cancelled")


{


  //making the closure information   tab visible


        g_form.setSectionDisplay('closure_information', true);   //Please check for the Tab name and change it


}


  else


  {


  //making the closure information tab invisible


  g_form.setSectionDisplay('closure_information', false);}


  }



Hope this will be helpful to you.



Thanks


Gopinath L


anubhavr
Giga Expert

Hi All,



I got the solution.



I can be done using Client Script 'OnLoad'.



function onLoad() {


  var st=g_form.getValue('state');



  if(st=='-5'|| st=='-4'|| st=='-3'||st=='-2') {


  var sections = g_form.getSections();


  g_form.setSectionDisplay('closure_information', false);


}


  else {


  var sections = g_form.getSections();


  g_form.setSectionDisplay('closure_information', true);


}


}