Custom Related List - Empty List field on Parent Causing Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 12:00 PM
When creating a custom related list to display user records from a list type field on the parent table, when the parent field is empty, the related list is showing ALL user records. (Script below);
Applies to table : custom table
Queries from table: sys_user
//Script to query list type field on parent (references sys_user)
var poi = parent.getValue("poi").toString().split(",");//array of users in list field
current.addQuery("sys_id", poi);
When there are user records in the parent list field, the relationship is accurate, however, when the parent field is empty (poi), the related list shows ALL user records. How can we provide validation on the parent field object to stop any query if the field is empty?
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 04:11 AM
Removed .toString(), so use this. It should work now.
var poi = parent.getValue("poi");
current.addEncodedQuery("sys_idIN" + poi);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 06:34 AM
I know this post is from a while ago, so maybe you solved this but I came across the same issue when trying to do this with a parent field. Although not perfect, I went with the following as a solution.
In the List Control configuration for that related list, I ticked the "Omit if empty" box, so that the related list would only show if there are items. Then in the relationship definition, went with:
(function refineQuery(current, parent) {
if(!gs.nil(parent.parent))
current.addQuery('parent', parent.parent);
else
current.addQuery('parent', "None");
})(current, parent);
The "else" condition could be almost anything really, as long as you are confident that it will return no results and therefore the related list will be omitted. This way if the parent field is empty the query will be amended to return no results, rather than showing everything with a null parent value.