How to hide an embedded list using a client script or UI Policy

mballinger
Mega Guru

Hello,

I have an ask to hide an embedded list onLoad() based off certain fields being populated. I am struggling to hide the embedded list. I have tried 2 different ways to hide the embedded list, but it is still not hiding. Please see below:

 

Method 1:

 

function onLoad() {

	var isDiscontinued = g_form.getValue('u_is_discontinued');
	if (isDiscontinued == 'yes') {
		g_form.hideRelatedList("REL:ced561fe1b6edd94e0b2feeccd4bedc5");
	}

}

 

Method 2:

 

function onLoad() {
        // Saw this method on snguru website
	var list = $$('div[tab_caption="Product Type"]')[0];
		if(list.hasClassName('embedded')){
			list.hide();
		}

}

 

I have tried both methods, and both methods are not working. 

 

Can someone please assist with this?

 

Thanks!

1 ACCEPTED SOLUTION

mballinger
Mega Guru

We were not able to make this work with the recommendations. What we winded up doing was creating a new section and then adding the embedded list to the section and used a client script to show/hide the entire section. Thanks!

View solution in original post

15 REPLIES 15

@mballinger I have tried the method 2 script with "Isolate script" field set to false in my PDI it was working fine. Please check if embedder list header is "Product Type" or not. And check if any space before or after "Product Type".

 

Inspect the embedded list element and check for "Product type" by doing CTRL+F like i searched for "Assets Covered"

jaheerhattiwale_0-1671599910508.png

 

Check if Product Type is correct or not in DOM element.

 

Client script i tried which is working:

jaheerhattiwale_1-1671599968114.png

 

 

Please mark as correct answer or helpful based on impact

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Community Alums
Not applicable

Hi there,

 

You can also write UI policy to achieve this. Please refer the below link which will be useful.

 

https://servicenowguru.com/scripting/client-scripts-scripting/hiding-related-lists-embedded-lists/

 

Regards,

Gagan k

reshmapatil
Tera Guru

Hi @mballinger ,

 

I tried using hideRelatedList() and it's working fine.

reshmapatil_0-1671265859850.png

 

 

For more details check:

https://servicenowguru.com/scripting/client-scripts-scripting/hiding-related-lists-embedded-lists/

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

mballinger
Mega Guru

We were not able to make this work with the recommendations. What we winded up doing was creating a new section and then adding the embedded list to the section and used a client script to show/hide the entire section. Thanks!

Would you mind please share an example of what ended up working for you please?

 

Thanks and yes running into the same issue.