The CreatorCon Call for Content is officially open! Get started here.

How to hide a related list if field is set to certain value

LyndseySharpe
Tera Contributor

Hi all,

 

I'm trying to hide the related list 'vendor catalogue items' on the company table whenever the form is loaded, if the approval status field is set to none or approved, and the vendor field is ticked. I've attached a screenshot here showing these details, circling the two fields on the company form that should determine if the related list is visible or not, and also the related list I'm trying to hide. I've also attached a screenshot showing my catalogue UI policy I've created, that isn't working. I've tried what's in this article below, and no luck! Anyone got any ideas or had something similar?

Solved: How do I hide a related list on load? - ServiceNow Community

Thanks!

Vendor fields condition is based on.jpg

LyndseySharpe_1-1671035639018.jpeg

LyndseySharpe_2-1671035659400.jpeg

LyndseySharpe_4-1671035698704.jpeg

 

 

 

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage

Rather than using script you can utilize UI Policy Related List Action.

UI Policy

MuhammadKhan_0-1671036841136.png

 

UI Policy Related List Action

MuhammadKhan_1-1671036892454.png

 

 

View solution in original post

7 REPLIES 7

Muhammad Khan
Mega Sage

Rather than using script you can utilize UI Policy Related List Action.

UI Policy

MuhammadKhan_0-1671036841136.png

 

UI Policy Related List Action

MuhammadKhan_1-1671036892454.png

 

 

As far as the script approach is related, your scripts would look like below.

 

Execute if true will contain below script.

function onCondition() {
	g_form.hideRelatedList('pc_vendor_cat_item');
}

 

Execute if false will contain below script.

function onCondition() {
	g_form.showRelatedList('pc_vendor_cat_item');
}

 

In case if you just want to hide that related list only on load of the form when conditions are met, then you can utilize below script.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var vend = g_form.getValue('vendor');
	var app_status = g_form.getValue('backend_name_of_approval_status_field');
    if (vend == 'true' && (app_status == '' || app_status == 'backend_value_of_choice_approved')) {
        g_form.hideRelatedList('pc_vendor_cat_item');
    } else {
        g_form.showRelatedList('pc_vendor_cat_item');
    }
}

Thanks so much, this worked! I can't believe I missed that extra tab, I use the first tab 'ui policy actions' all the time 🙈