Operator Scope of Action:
Operator First Added:
The property .count counts the Number of discrete items in the specified List or Set data type attribute.
The subject list is evaluated so can use a literal list or $attribute(note). It can also use more complex expressions to get data - as long as the result is an attribute of the List or Set data type.
For example if $KeyAttributes for the current note is "Color;Color2;NameFont" then the code
and not surprisingly returns 3. Note that the count is not all unique values for the attribute across the whole TBX - scope is restricted to 'this' note or another nominated note. Specimen usage:
$KeyAttributes(some other note).count
.count with a list of items that are attributes or expressions, use
list() to pre-create a list:
$MyNumber = list(4+2,9+6).count (output: 2)
For more complex examples, where list items are action code expressions, it may be necessary to use eval() to wrap each list item expression e.g.
The following is a trivial example (given you could use $ChildCount instead) but shows how count can be used in a more subtle way:
$MyNumber = collect(children,$Name).count
The result of collect() is a List, in this case a number of note titles.
List.count will return the number of values in the list (including duplicates). To get a de-duped count, chain the
.unique function before the
$MyNumber = collect(children,$Name).unique.count
Similarly, find() returns a List but note that find() does not de-dupe for aliases. Thus test $IsAlias in the query to weed alias results from the returned list:
$MyNumber = find($Prototype=="pProject"&$IsAlias==false&$ChildCount>1).count