cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dfajfjaf
Frequent Visitor

after creating new item in SharePoint list, how to get the 2nd last item?

Hi,

 

I'm trying to get the 2nd last item from a SharePoint list.

 

To explain:

- a flow is triggered when a new item is added to a SharePoint List.

- I want to add a number to the new item that is one larger than the previous item (essentially a tracker ID)

- so my flow is triggered by 'when an item is created'

- I'm then initialising a variable (which I want to set to ID number from the previous final list item).

Can you advise?

 

dfajfjaf_0-1649764912552.png

Thanks in advance

3 REPLIES 3
Rhiassuring
Super User
Super User

Hi there, 


I suspect the easiest way would be to go Current Item ID (SharePoint's auto-generated ID, that is) minus 1, and then use that number as the ID for the "second to last item". From there you can grab whatever you need from the item and update the custom ID. 

Would that work? Unless there's a constant deletion of items from this library making the ID not trustworthy, I think it would do the trick.

(My other comment is that if you are generating a schema for documents / files, it can be good to have a central place where all schemas are managed, in a list, and makes this kind of thing a bit easier / cleaner - you just query the list of the schema you want to use, get the last ID used, and increase it by 1, then update the file and the schema tracker. Fun document control stuff!) 

Cheers,

 

Rhia

dfajfjaf
Frequent Visitor

this seems like a very elegant solution - many thanks for suggesting it.
I'll be trying it over the next few days and will make sure to reply if it works.

 

Thanks again

Hi,

I'm failing at how to actually do the 'minus 1' activity. I'm trying to do a get item with an ODATA filter - is this the correct approach?

 

Thanks

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (3,340)