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 ->
daniels9627 Thanks for confirming what you were looking for & If you are willing please hit 'Verify answer'.
I am not sure whether a recursive approach is the best option for this. I wrote a blog post about how to implement more "complex" algorithms in Appian.
https://appian.rocks/2022/08/29/complex-algorithms-in-appian/
Certainly, I'm also uncertain, and I attempted to implement binary search in Appian using a recursive approach. Surprisingly, this consistently takes more time than a straightforward linear search. I'm puzzled by this because, as we understand, binary search typically has a time complexity of log(n), while linear search has a time complexity of O(n). Could it be attributed to calling an expression rule or passing substantial data through RI(s) multiple times?and yes I'm gonna read that. Your blogs, as well as Harshit's blogs, are rich in information and contain sharp details.