<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Document in Folder</title><link>https://community.appian.com/discussions/f/best-practices/33936/document-in-folder</link><description>Hi All 
 Newbie to Appian. 
 Trying to find, by date &amp;amp; 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, &amp;quot;documentChildren&amp;quot;), 
</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128802?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:14:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:222a1f8c-0dbc-4166-8512-16d7dccdde2f</guid><dc:creator>daniels9627</dc:creator><description>&lt;p&gt;Pleasure!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128801?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:14:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c943de56-da55-49ac-9303-704f349b1b86</guid><dc:creator>daniels9627</dc:creator><description>&lt;p&gt;Thanks Harshit, works nicely!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128800?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:13:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:92051ce8-cb10-4e57-b30a-4e28d471f92a</guid><dc:creator>Stefan Helzle</dc:creator><description>[quote userid="263493" url="~/discussions/f/best-practices/33936/document-in-folder/128797"]read through most of Stefan&amp;#39;s book[/quote]
&lt;p&gt;Very much appreciated :-) Welcome to Appian!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128798?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:08:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:df0c9823-011d-47de-9f1a-90c5915d3c46</guid><dc:creator>Harshit Bumb (Appyzie)</dc:creator><description>&lt;p&gt;The document ID will always be incremental as Amaan mentioned and can be relied on. But here is an alternate approach with one of my favorite functions - displayValue() using the created date attribute&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!documents: a!forEach(
    items: folder(5, &amp;quot;documentChildren&amp;quot;),
    expression: a!map(
      id: document(fv!item, &amp;quot;id&amp;quot;),
      dateCreated: document(fv!item, &amp;quot;dateCreated&amp;quot;)
    )
  ),
  local!maxDate: max(local!documents.dateCreated),
  displayvalue(
    local!maxDate,
    local!documents.dateCreated,
    local!documents.id,
    {}
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128797?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:07:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2bd414e3-453c-4229-9a5c-0321fea91dca</guid><dc:creator>daniels9627</dc:creator><description>&lt;p&gt;Thanks All&lt;/p&gt;
&lt;p&gt;I have done the Associated and Applied Developer courses, read through most of Stefan&amp;#39;s book, and now going through the online resources/videos/tutorials and also trying my own apps, so I am on the road! (the Great Appian Way Road).&amp;nbsp; So you will probably see me again posting questions!&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Thanks again for your reply&amp;#39;s!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128792?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 16:02:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:374bce83-790d-4e49-b91f-f4a15d73c8a7</guid><dc:creator>EREN_YEAGER</dc:creator><description>&lt;p&gt;&lt;span&gt;Certainly, I&amp;#39;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&amp;#39;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?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;and yes I&amp;#39;m gonna read that. Y&lt;span&gt;our blogs, as well as Harshit&amp;#39;s blogs, are rich in information and contain sharp details.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128783?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:52:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dbaa7d46-b9e4-459e-9d52-6306713b9e35</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;I am not sure whether a recursive approach is the best option for this. I wrote a blog post about how to implement more &amp;quot;complex&amp;quot; algorithms in Appian.&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://appian.rocks/2022/08/29/complex-algorithms-in-appian/"&gt;https://appian.rocks/2022/08/29/complex-algorithms-in-appian/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128782?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:48:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:211437b8-ae27-42f7-9106-db4ab5396372</guid><dc:creator>EREN_YEAGER</dc:creator><description>&lt;p&gt;&lt;a href="/members/daniels9627"&gt;daniels9627&lt;/a&gt;&amp;nbsp;&lt;span&gt;Thanks for confirming what you were looking for &amp;amp; If you are willing please hit &amp;#39;Verify answer&amp;#39;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128781?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:45:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:974844e9-2949-45b3-aebb-d408b0c36735</guid><dc:creator>EREN_YEAGER</dc:creator><description>&lt;p&gt;&lt;span&gt;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.&lt;/span&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: a!forEach(
    items: folder(6025, &amp;quot;documentChildren&amp;quot;),
    expression: document(fv!item, &amp;quot;dateCreated&amp;quot;)
  ),
  rule!DCT_getMax(
    array: local!data,
    currentMax: property(local!data, 1, null),
    currentIndex: 1,
    lengthOfArray: length(local!data)
  )
)&lt;/pre&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;code for DCT_getMax -&amp;gt;&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;if(
  ri!currentIndex &amp;gt; ri!lengthOfArray,
  ri!currentMax,
  rule!DCT_getMax(
    array: ri!array,
    currentMax: if(
      ri!currentMax &amp;gt; ri!array[ri!currentIndex],
      ri!currentMax,
      ri!array[ri!currentIndex]
    ),
    currentIndex: ri!currentIndex + 1,
    lengthOfArray: ri!lengthOfArray
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/20/pastedimage1706888679277v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;result -&amp;gt;&amp;nbsp;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/20/pastedimage1706888711177v2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128780?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:41:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:97e9fa95-f2e9-49a8-939d-5c784d4ba050</guid><dc:creator>daniels9627</dc:creator><description>&lt;p&gt;Thanks Amaan, this worked, nice little trick.&amp;nbsp; One step forward :&lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f600.svg" title="Grinning"&gt;&amp;#x1f600;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128778?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:28:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3e37aa2d-7ed6-44bc-ac43-4d9cbc5b1d5b</guid><dc:creator>EREN_YEAGER</dc:creator><description>&lt;p&gt;I don&amp;#39;t know if this will work for you or not but as far as I&amp;#39;ve seen recent document will have greater document Id then previous ones, so here is the code for getting most recent uploaded document -&amp;gt;&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;max(
  a!forEach(
    items: folder(6025, &amp;quot;documentChildren&amp;quot;),
    expression: document(fv!item, &amp;quot;id&amp;quot;),
    
  ),
  
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Document in Folder</title><link>https://community.appian.com/thread/128776?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 15:10:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:56378c7e-ff1d-4e43-a961-36bf2d49f6f2</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;Let me first ask my usual question. What do you want to achieve? We typically just dump documents to folders and store the required meta data to database. Then your question can be answered by a simple query.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>