We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

16 REPLIES 16

Hi, method 1 only works for Related Lists but here we are talking about Embedded Lists (not the extra lists at the bottom but the table as part of the form).

 

We got method 2 to work by scripting the following:

var list = document.querySelector('div.tabs2_list[tab_caption="' + tabCaption + '"]');
if (list) {
	var wrapper = list.closest('.custom-form-group');
	if (wrapper) {
		wrapper.style.display = 'none';
	}
}

 

ayab
Tera Contributor

Method 1 worked for us, except we put the table name as the argument

g_form.hideRelatedList("table_name");