How to identify the most recently modified Note in a Container

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:

ContainerX, whose $DisplayExpression = Name+" Last Modification: "+$MyDate
'–> Note 1
. '–> SubNote 1a (created 2023-11-24)
'–> Note 2
. '–> SubNote 2a (modified 2023-12-01)
. '–> SubNote 2b (modified 2024-01-20)

Where $MyDate = 2024-01-20

Does this work for you?


Edit: Corrected spelling of descendants (though TB accepted descendents)


[Edit: originally collected oldest, not newest, but same principle holds]

See Sorting Date-type data. OK:

// 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 =;

or in single-line form:

$MyDate = collect_if(descendants, $Modified!="never",$Modified);

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:

$MyDate = collect(descendants,$Modified);

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]

1 Like

Thanks much!! Will try both these great approaches.