Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

hide or show a related list.

ravigajananjosh
Mega Contributor

I have a requirement on Incident table to hide or show a related list. I have introduced a new choice field on Incident - BreakGlass which has choices Yes or No. Also I have a Related list on Incident i.e BreakGlassRequests which lists all break glass requests done for that incident. What should happen is untill I take Yes in BreakGlass field the BreakGalssRequests related should be hidden. I tried this function onCondition() { g_form.showRelatedList(BreakGlassRequests); } in UI policies in SCripts but thats not working. Can some one help me with this?

9 REPLIES 9

Bharath40
Giga Guru

Hi Ravi,



Try with a Onchange client script



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


    if (isLoading || newValue == '') {


          return;


    }


    var myValue = g_form.getValue('Break_glass');


  if(myValue == 'true'){


  g_form.showRelatedList("BreakGlassRequests");


  }else{


  g_form.hideRelatedList("BreakGlassRequests");


  }


}


Pradeep Sharma
ServiceNow Employee

Hello Ravi,



Here you go.


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



  var brkGlass = g_form.getValue('u_break_glass'); //Assuming u_break_glass is the exact column value


  if(brkGlass == 'yes'){ //Replace yes with the exact choice value of the field breadk glass


  g_form.showRelatedList("BreakGlassRequests"); //Make sure you pass the name of the related list


}else{


  g_form.hideRelatedList("BreakGlassRequests"); //Make sure you pass the name of the related list


}


}


No mates, both the scripts doesn't seem to be working. If I go to the Incident form initially the BreakGlassRequests will be Off. As soon as I create a record it will appear. Now ideally when I toggle the choice to Yes the breakglassRequests related list should appear and when I toggle it to NO it should disappear


. servicenoehiding.jpg


Just a correction in the screenshot. In the field I have made it BreakGlass. Also I have put the alert messages in few places. But still the BreakGlassRequests tab behaves the same way. Once I create a record it will be ON and if I change it to NO even it remains ON. No clue whats happening here.