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

@SanjivMeher - Thanks for you response! Yes, the name of the embedded list is correct in Method 2. I used the browsers inspect tool to grab the name. 

 

This is not on service portal

jaheerhattiwale
Mega Sage
Mega Sage

@mballinger Tried and tested solution.

To make the script in "Method 2" work, you must uncheck the "Isolate script" field on client script.

jaheerhattiwale_0-1671252884282.png

 

If the field is not present on the form then go to list view and uncheck it.

jaheerhattiwale_1-1671252948051.png

 

 

Please mark as correct answer if this solves your issue.

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

@mballinger Did you try this?

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

@jaheerhattiwale - Thanks for your response! I removed the isolate script, and it is still not working using the method 2 approach.

@mballinger Can you please post the screen shot of code?

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