cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
duncant
Helper V
Helper V

Get Most recent item from SharePoint List

I have created a flow to get the most recent response from a SharePoint List based on the SharePoint ID value.  I have created a temp variable (tempId) initialized to 0.  If the SharePoint List ID is greater than the tempId, the tempId is set to the SharePoint List ID. The tempId it set correctly, but when I try to use the tempId to Get an item, it is something completely different.  

 

 

Capture1.PNG

 

Capture2.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Community Champion
Community Champion

The results returned by Get items action is an array (the value property). To access all the items in the array (even if there is only one item in the array) Power Automate uses the Apply to each loop.

 
 

2021-10-14_15-10-18.png

To avoid using the Apply to Each loop when we only have one item, we can use an expression:

ekarim2020_2-1634221059299.png

But there is nothing wrong with using the Apply to Each loop if you want to.


Ellis

 


____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
ekarim2020
Community Champion
Community Champion

I would need to see the flow to understand what you are trying to achieve and how. But here is one method to get  the newest SharePoint item that was created - which will be the item with the highest ID:

ekarim2020_1-1634163108499.png

The ID stored in a variable:

ekarim2020_0-1634163095479.png

The variable used in a Get item action:

ekarim2020_2-1634163383545.png


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

@ekarim2020 I am trying to get the most recent response.  Instead of ID desc, I used Created desc and Top 5 (I've noticed although you choose one, more items are pulled).  I will try using the ...['body/value'][0]... instead.

 

Capture3.PNG

 

Capture4.PNG

 

ekarim2020
Community Champion
Community Champion

The following will get the most recently changed or modified list item from SharePoint:

2021-10-14_14-48-52.png

 


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

@ekarim2020 When you initialize the variable, does this create an apply to each? 

ekarim2020
Community Champion
Community Champion

The results returned by Get items action is an array (the value property). To access all the items in the array (even if there is only one item in the array) Power Automate uses the Apply to each loop.

 
 

2021-10-14_15-10-18.png

To avoid using the Apply to Each loop when we only have one item, we can use an expression:

ekarim2020_2-1634221059299.png

But there is nothing wrong with using the Apply to Each loop if you want to.


Ellis

 


____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

@ekarim2020 I think I am getting the apply each while inside another apply to each, which is why I cannot initialize the variable to that value.    Instead, I went ahead and set the top count to one, got the ID directly, and removed the tempId variable. 

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,044)