“I’m creating custom id for each new SP item, how do I get the latest one so I can increment it within Power Automate flow?”
When creating basically any data (not only in SharePoint), you should always have a unique ID. It’s so much easier to reference a specific entry / request / anything if you can share just a single, unique value!
While SharePoint assigns their own ID to everything, it’s often not in the format you might like. It’s just a number, nothing else, and it starts from 1 in each list you use. No fixed length, no letters referencing the solution, only a number. Yet an ID like REQ-0001 might look so much better than just 1.
Utilise the SharePoint ID
One way to create a unique ID is to start from the SharePoint ID and extend it. The benefit of this approach is that the item ID is always unique. Even if you create 10 items at the same time, they won’t compete about the ID, they’ll all get their own.
The downside is that this solution always needs two steps – to get the SharePoint ID you must create the item. ‘Create item’ the item, take the item ID output of that action, use it to create the actual ID and update it.
You must also keep in mind that once a SharePoint ID is used it’s not available anymore in the list. For example, if you delete items from the list the IDs of those deleted items won’t be available anymore. You can easily create a hole in the ID sequence if you’re not careful.
With that in mind I’d say this is still the best solution. If you have just one custom ID sequence, you can use the IDs directly in the list. If you need more than one sequence you can create multiple ‘side’ lists, each of them used only to track the specific sequence. Create item in the side list, take its ID, and use it to create item in the main list.
Continue from the latest custom ID
The other approach, in case you use various custom IDs in a single list, is to search for the last ID so that you can increment it. Use the ‘Get items’ action with a filter and sorting to find the last item as already explained. Add 1 to the ID number and use it to create the item.
There’re a few things to be careful about as well though. Firstly, you’ll have to also check whether such ID was even used before. Secondly, you must extract the number from the ID to be able to increment it and turn it back into ID. And thirdly, the most serious issue – there’s a risk that the ID won’t be unique. If you create 10 items at once, they’ll all get the last item, increment its ID, and use it. For this reason you should always run only one such flow at a time.
That’s a bit too many potential problems and a reason why I’d avoid this approach.
Summary
When you need a unique, custom ID that’ll be created within your Power Automate flow, it’s a good idea to use the standard SP functionality. SharePoint will take care of any parallel requests for you, all you need is to create an item in some list, take the ID, and use it to create your custom ID. Unique number to which you just add the remaining characters.