Custom Related List - Empty List field on Parent Causing Issues

TCole94
Tera Expert

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?

6 REPLIES 6

@TCole94 

Removed .toString(), so use this. It should work now.

var poi = parent.getValue("poi");

current.addEncodedQuery("sys_idIN" + poi);

Sam Earl
Tera Guru

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.