What’s the best method to go about identifying the date of the most recent modification to a Note in a Container? The constraint here is that the (most recently modified) Note might be 2 or 3 levels down. What I’m looking to do is:
// collect $Modified for descendants, weeding any default dates
var:list vList = collect_if(descendants, $Modified!="never",$Modified).sort;
// Set $MyDate to the last, i.e. newest, date
$MyDate = vList.at(-1);
Note, we are dealing with $Modified, which is always set for any note: it defaults to the value of $Created. So like $Created, but unlike most Date-type attributes, in this scenario it is not possible for a note to have a $Modified values of never, so you could omit the ‘if’ query and use:
So you have a solution for the stated case and for testing date-type attributes in general. The key is knowing if a “never” value may turn up and if it does where it will sort, at discussed in the linked article above. Note the pattern for wider use of Date attributes as a value of “never” sorts last in a lexically-sorted list. By using collect_if() you can ensure the list only has actual dates.
[Edit: If you did want the oldest date use .at(0) in the code examples above]