How to display records in a related list based on a condition ?

Ritesh26
Tera Contributor

Hi All,

I have created a relationship between incident and problem. This will give the list of the problems with the same CI and that has atleast 1 major incident attached.

find_real_file.png

This relationship has been added to the related list of the Incident form.

find_real_file.png

Now my requirement is that, I have major incident (checkbox) on the incident form. Only when this checkbox is selected, the records in the related list should be displayed. If it is unchecked, the records should remain hidden.

How do i go about doing this ?

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ritesh,

So you can use this. show the related list if checkbox is true; hide the related list if checkbox is false

function onLoad(){

var value = g_form.getValue('major_incident');

if(value.toString() == 'false')

g_form.hideRelatedList('nameofrelatedlist');

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur has beaten me to this but i'll just add, if it's a relationship the name will REL:sys_id eg:

g_form.hideRelatedList('REL:aee27790374ff70044fe03a973990eaa');

Ritesh26
Tera Contributor

Hi Ankur,

g_form.hideRelatedList('nameofrelatedlist');

This hides the related list. But what I require is that the related list should stay, but only the records should get displayed when the major incident checkbox is checked.