- 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-14-2022 02:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 12:06 AM
Hi,
are you saying based on some form field value you need to show/hide the related list?
can you explain your complete requirement?
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-14-2022 01:23 AM
are you saying based on some form field value you need to show/hide the related list?
Yes, that is the requirement. Based on a field value on the parent form (i.e. form view on which the related list will be shown), I need to hide or show it.
This also includes the requirement of not having to look for related records if I've to hide the related tab.
So in short:
(a) When tab needs to be showed, sure go ahead and query the related table
(b) When the tab needs to be hidden, do not even attempt to query the related table since I do not want that information at all (it is possible that there might still be records in the related table when I'm hiding the tab)
For example:
Field which decides the show/hide condition: Customer status = "Active"
Related table: Orders placed by that customer
Logic:
if( customer status == active)
{
// show the orders tab
}
else
{
// hide the orders tab
// inactive customers may also have had some orders placed but I do not want to query for them
}
Hope this makes sense
- 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-14-2022 02:08 AM
I'm not quiet sure how much effect using "-1" will have (i.e. whether it will still traverse through all records to find the matching sys_id or will it skip it completely) but this is something that will at least guarantee 0 records in case status condition is not matched.
So I'll tentatively mark it as answer but might come back after performing some SVT.