Is it possible to show related list conditionally?

Nisar2
Mega Guru

Hi experts,

I've a related list defined on a table. I would like to show this tab only on certain conditions. What would be the best way to achieve this? The screenshot below should define what I'm trying to do

find_real_file.png

 

One way I can think of is making this return 0 rows so that I can then go to "Right Click->Configure Control->Omit if no records"

But I would be all for not having to query that table at all since it contains 3M+ records and querying through such a large dataset is delaying loading of form on the parent table

1 ACCEPTED SOLUTION

Do this

parent object gives you access to current form field values

if(parent.status.toString() == 'active'){
	// use your query to show
}
else{
	current.addQuery("sys_id", "-1"); // no records returned using this
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

22 REPLIES 22

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onLoad client script and based on your condition show/hide the related list using example

g_form.hideRelatedList('task_ci');

Hiding Related Lists and Embedded Lists

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

What about the order of execution?

If this client script runs after the source table has been queried, then wouldn't it defeat the whole purpose? What I'm trying to do is not query the table at all if some condition fails.

Hi Nisar,

 

What about an if condition before the query. You check if the current record on Apply to table meets the condition (I hope it's a field value). Of course the related list will run but it won't query from the Queries from table. Then use the same condition in hideRelatedList.

So when the related list is displayed, then only it will be quering records from the Queries from table.

How would this work? What would I put inside the "if" condition? I tried with "return false" or just "return" and it fetched all the records of the "Queries from Table"