How to retrieve the value of the primary key in a creation flow

I’m trying to retrieve the value of an auto increment primary key in an item creation flow so I can use it in a calculation for a generated field. It seems like this might not be possible? Is there some other way to created a calculated/generated field based on the item ID?

You can only get the key for item.create when the flow is of type Action (Non-Blocking), as that way the item has been created before the Flow runs (so the key exists). However, this does means that if you want to perform some sort of calculation and write the result back to a field within the same item, you can’t always guarantee that that will have happened before the page is refreshed. It’s possible that if the user presses “Save And Stay” on the new item, the page will refresh, the flow will run, but the flow may still be running by the time the page refreshes meaning the user does not see the updated data unless they manually refresh the page again. In practice, I find this doesn’t really matter in the case of a simple calculation as it usually happens quick enough that the page refresh will show the new data okay. Just something to be aware of if you’re doing something complex.

If the flow is set to Filter (Blocking), the item hasn’t actually been created yet by the time the Flow runs, so you can’t get the key for the new item as it doesn’t exist yet. If your key is an auto-incrementing integer though, I guess you could just read the collection in your first operation to find out what the id of the most recent item is, and assume that the id of this new item will be that plus one.