- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 09:14 PM
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
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 01:59 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 10:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 10:13 PM
What about the order of execution?
If this happens 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 10:18 PM
hello,
Write a onload client script:-
In the if loop write the below:-
g_form.showRelatedList('tablename');
in the else writhe the below:-
g_form.hideRelatedList('tablename');
So this will keep the related list hidden till the condition matches.
Please mark answer correct/helpful based on Impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 10:42 PM
I once again ask - if this piece of code runs after the source table has been queried, then it introduces delay in loading the form view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2022 11:05 PM
hello,
Did you try the code and did it introduce a delay or is it just an assumption?
Thanks.