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

Claude DAmico
Kilo Sage

Try using an if statement to confirm it is not empty.

var par = parent.getValue("poi").toString();
if(par !== ''){
   var poi = par.split(",");//array of users in list field
   current.addQuery("sys_id", poi);
}
Claude E. D'Amico, III - CSA

I tried using use that script and unfortunately with an empty list field, it is still returning all records from the user table.

Muhammad Khan
Mega Sage
Mega Sage

Hi,

Try this

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

current.addEncodedQuery("sys_idIN" + poi);

Unfortunately that doesn't work either for empty or non-empty list fields.