Hi All
Newbie to Appian.
Trying to find, by date & time, the latest (most recently uploaded) document in a folder; this is as far as I have got in an expression I am playing around with:
a!forEach(
items: folder(1234, "documentChildren"),
expression: document(fv!item, "dateCreated")
)
Any good examples to help me finish this off, or can anyone suggest how to loop through each document and return the newest?
Example Algorithm in pseudo code I would like translated to Appianese.
MostRecentlyUploaded = initial ‘zero date’
For Each Documents Creation Date
If Documents Creation Date > MostRecentlyUploaded Then
MostRecentlyUploaded = Documents Creation Date
End if
End For
Return MostRecentlyUploaded /* The most recent date */
Thanks
Daniel
Discussion posts and replies are publicly visible
I don't know if this will work for you or not but as far as I've seen recent document will have greater document Id then previous ones, so here is the code for getting most recent uploaded document ->
max( a!forEach( items: folder(6025, "documentChildren"), expression: document(fv!item, "id"), ), )
Thanks Amaan, this worked, nice little trick. One step forward :
Alternatively, you can adopt the method you outlined in the post using pseudo code. This approach enables you to obtain the maximum value of any type within an array with minimal adjustments.
a!localVariables( local!data: a!forEach( items: folder(6025, "documentChildren"), expression: document(fv!item, "dateCreated") ), rule!DCT_getMax( array: local!data, currentMax: property(local!data, 1, null), currentIndex: 1, lengthOfArray: length(local!data) ) )
if( ri!currentIndex > ri!lengthOfArray, ri!currentMax, rule!DCT_getMax( array: ri!array, currentMax: if( ri!currentMax > ri!array[ri!currentIndex], ri!currentMax, ri!array[ri!currentIndex] ), currentIndex: ri!currentIndex + 1, lengthOfArray: ri!lengthOfArray ) )
result ->