Custom Relationship (Defined Related List)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 04:12 AM
I am trying to created a custom related list (Relationship menu) and able to setup the fields, script etc.
I am trying to not show the related list if it has no records. So I have set the 'Omit if empty' to true on list control.
Below is the format of my related list query script currently.
if(validData)
{
addquery to show the required data
}
If I am leaving the else part blank, it is end up pulling all the records from the table.
How would I handle the else part to return no data other than adding a invalid query? Is there a elegant way to do this?
- Labels:
-
Best Practices
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 06:48 AM
And it prints 0 when I log it on related list but I still see 50 records in the list. That's strange !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 07:15 AM
Wait a minute, I think I got it, a list view adds by default a LIMIT 0,X on the SQL based on the rowcount preference (where X is the value for your rowcount preference), so adding a setLimit(0) makes no sense in this particular case. So, yes, use your workaround with sys_id, as my idea was not useful for this case.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2017 07:21 AM
Does makes sense, as my preference is currently set to 50.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2017 01:44 AM
Hi
When defining a custom relationship, leaving out the script will pretty much return all the records (ACLs can have an impact) from the table populated in the Queries from table field. When using the if condition and it evaluates to false, the addQuery gets skipped and the platform will return all the records. So, you would need to add a query that will (or try to) return records.
This is where I'm a little confused about the question. When I see an if statement it suggests to me you have a logical pathway to build up alternative queries, so would expect to see an else if or else.
Should you stick to the existing addQuery without the condition and, as a result of the query, it returns no records wouldn't that lead to the desired outcome?
For example, let's say you use the out-of-box Attachment relationship (/sys_relationship.do?sys_id=b9edf0ca0a0a0b010035de2d6b579a03) on the Incident form and select Omit if empty, then you load up an Incident with no attachments this related list will not appear. Because the condition is looking for any records on the sys_attachment table with the Incident's sys_id and none are found.
Clearly, I'm missing something in your question. Please do give a bit more about the scenario and how the query would be invalid.
Many thanks
EDIT: Had a light-bulb moment as soon as I submitted my reply. If you are using variables within the condition and you're trying to guarantee a value, you could play around with the glide.invalid_query.returns_no_rows property.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2017 09:55 PM
I am trying to use the parent field of the record and show the parent field's record data on the related list.
Example, change has parent field containing RITM sysid.
In the 'if' block I am checking if the parent record is a RITM or not. If it is a RITM display the record else
If it is a RITM, display the record else do not show anything.
Does that answer your question on why I am using an if block?
If the parent field has any record other than RITM, I should not show it on the related list.