Dynamically hide Related Lists in ServiceNow
Say you wanted to hide this Incident Tasks related list based on certain criteria, how would you go about it?
One simple solution we have for you is by using a client script, follow along below.
Get the List Name
First of all, you'll need to find the List Name. We do this by using our browsers developer tools (in most browsers you can usually hit F12, or use your browsers settings or hamburger icon).
What we want to look for is the related list in the code, you can find this quickly using the selection tool and then clicking on the related list.
Within the "aria-controls" parameter hides the name of the related list. The first part we ignore, as it is the current table our related list is sitting on (in the above case incident). The list name for us in the above example is "incident_task.incident_list".
Create an onLoad Client Script
Next, create an onLoad client script on the table of the record you are viewing that has the related list in question (don't create one on the related list's table).
Add any business logic necessary to dictate when the lists should show or hide (perhaps you only wish to hide it if certain field values are present), then include the following lines of code in the script field in order to either Show or Hide the list.
That's it!
Comments ()