
AndyC.64975 (Customer) asked a question.
My colleague and I are stuck on how to construct a workflow that increments an integer in the last position of a username.
In workflows we have lookup table of all our organisation's usernames. We are building new user workflows and want to construct a unique username by incrementing an integer in the last position if that username is found. We have built a method that searches the table, finds a match then increments the integer. We then put that username2 through the search again - we figure that 9 loops will be enough but I'm expecting there to be a much more elegant way to do this. Any ideas?

Hey @AndyC.64975 (Customer) - you have a loop in case you have username8 in the table?
I've been nesting IF Else cards. How would you do it?
Updated post as the previous solution wouldn't have worked past essentially Username20. See screenshot this meets use case.
So this will allow you to infinitely increment the username.
Next, you need to do a loop. This is no different than what you see in most languages where it is i=1, i++.
This would all need to take place in Helper/Child flow. You would need to set a "increment" counter number as one of the values in the Helper/Child. The first step after the Helper/Child would be to increment the value by 1. (An empty int field starts as 0.)
The flow would then run checking to see if the "incremented number" is less than X. If it is less than do the "True" branch. If it is greater than do the "False" branch.
The outputs from the if/else would go to a "Call flow" card that is configured to call the Helper/Child flow you are currently in. This then would update the username with the incremented value, and pass the incremented counter for the next pass. This would repeat until the counter is greater than the If/Else evaluation above which would lead to the False branch.
You will also need to put in something like a continueIF card right before the call flow that also makes sure the increment is under X to ensure the flow stops before call flow is called again.
Updated the flow.. some changes. The above flow doesn't handle 2 conditions: username (no int on the end) and (user1name) and int somewhere not at the end. See new screenshots (Same flow just longer now).
Thanks Tim.
We couldn't get the child flow to return the new values to the parent, but that spurred us on to create a more elegant solution by modifying the username table i.e splitting out the username numeric into its own column, thereby allowing us to easily pull out all relevant records using table search and then find the highest number.
All this would have been so much easier with a 'contains' function in the table search card.