Not able to hide related list using g_form.hideRelatedList / hideRelatedLists

Anubhuti Mittal
Tera Contributor

Hi Team,

I have 4 related lists on my page , and i want to hide/show 2 of these under certain conditions.

I have tried the following but nothing seems to work for one of the related list

g_form.hideRelatedList('REL:sys_id');

g_form.hideRelatedLists()
g_form.hideRelatedList('<related list name>');
the 2nd list is easily hidden using any of the above.
4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Can you show what related list is hidden and what is not? And what script have to tried?

Screenshot of related list and script you have tried

 

whichj one of it worked on second one?

-Anurag

AnubhutiMittal_0-1734963434093.png

 

AnubhutiMittal_0-1734963895085.png

L1 : Penetration Test Findings 

L4 : Penetration Test Findings NPT

The 2nd one is UI Policy

 

Runjay Patel
Giga Sage

Hi @Anubhuti Mittal ,

 

Create UI Policy with condition and create "UI policy related list action" instead of writing code.

RunjayPatel_0-1734964227493.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

Anand Kumar P
Giga Patron
Giga Patron

Hi @Anubhuti Mittal ,

 

Instead of passing just the sys_id of the defined relationship, you will also need to prepend it with the following string 'REL:'

The syntax will be as follows:
g_form.hideRelatedList('REL:sys_id');

 

g_form.hideRelatedList('REL:70e80f390a0a0b1b0035a51d8bbfd32c');

 

Go to System Definition > Relationships and search for the table relationship associated with your related list name .

 

Example screenshots:

Navigate as below System UI -> Related Lists

 

AnandKumarP_0-1734977322475.png

 

 

AnandKumarP_1-1734977322318.png

 

 

 

In script screenshots which you pasted that will hide form sections not related lists, if you want to hide related use above approach with correct relationship names.

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand