Tech Tip: Utility method to get all distinct values for field
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: July 11, 2022
Below is a method that outputs a collection of all distinct values for a field, given a table name and field name.
#DECLARE($table : Text; $field : Text)->$distinctValues : Collection If (Count parameters=2) If (ds[$table][$field]#Null) $distinctValues:=ds[$table].all().distinct($field) End if End if |
The above method could be useful for obtaining distinct field values to set up a pivot table in a View Pro sheet, for example. Note that if the input table or field names are not valid, the method will return null.