cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hnguy71
Level 8

Retrieve last record ID from SharePoint list

Good morning,

I have a test flow where I want to just retrieve the last record ID within the list. In theory, what I want is to find the last item and then the first item in the list, divide all of that by 4000 to find how many iterations I need to loop, and finally delete every single record from there, but let's take a step back and figure out my first problem.

I have a variable that I'm initliazing and within the array, I want to return the first ID with this code but it's currently not working:

Body('Get_items')[0]?['value']?['ID']


here's my current setup:
get_last_ID.png

 

And here's the error that I'm receiving:
error.png

 

Any ideas on how to fix this?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Retrieve last record ID from SharePoint list

Hi @hnguy71 ,

 

I noticed that the expression you used seems to be incorrect.

Please try to get the last item using the expression below.

body('Get_items')?['value'][0]['ID']

37.PNG

Please try again.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Super User
Super User

Re: Retrieve last record ID from SharePoint list

@hnguy71 

As I understand it, your first goal is to find out how many items are in the list.  Here is an alternate approach:

ListCount.jpg

 

The variable holds the total number of list items.

Remember to go to settings for the Get Items action and set pagination on and set the threshold to a max of 5000 unless you have a P2 license.

 

If you will be using a do until loop when you delete the items, remember to click "change limits" in the loop and set the count to a number tat makes sense - the default maximum loop limit is 60.

 

 

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

Scott
Highlighted
hnguy71
Level 8

Re: Retrieve last record ID from SharePoint list

Hi @ScottShearer ,

that only gives me back a maximum number of 5000. I was able to accomplish this in a different way. I used an apply_to_each and since I only have 1 item, I'll set the last record variable to just that 1 ID.
apply_to_each.png

 

From there I set a variable to see how many iterations I need to purge the entire list:

add(div(variables('_LastRecord'), 4000), 1)

iterations.png

 

And I'll likely create an array to loop through them but I got further than I expected. I don't have a large list to try this out on but haha so far it looks like it's working. Thanks for the help!

Community Support Team
Community Support Team

Re: Retrieve last record ID from SharePoint list

Hi @hnguy71 ,

 

I noticed that the expression you used seems to be incorrect.

Please try to get the last item using the expression below.

body('Get_items')?['value'][0]['ID']

37.PNG

Please try again.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hnguy71
Level 8

Re: Retrieve last record ID from SharePoint list

Ahhh! The [0] was in the wrong place! Thanks for the help!

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

thirdImage

New Flow Community Board!

Check out the new Microsoft Flow Community Blog Topic Suggestion board!

fourthImage

Australia Summit

Travel to Melbourne and network with thousands of peers!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 105 members 4,381 guests
Please welcome our newest community members: