Increase number by "001" and retry entry activities

I am trying to create Officer Codes. To do this, I start with 3 letter characters and then add to it a number starting at “001”. For example, JDE001. Then if that Officer Code is already assigned in our system, I get the message “Officer already exists”.

If I receive this message, I need to increase the number by one (JDE002) and try to enter it again until the Officer Code is created.

I have tried to search for other users with similar issues to increase the number portion, but none of the examples are working.

Create variable counter with Default value 1
Create boolean variable OfficerExists

  • Do While (condition OfficerExists)
    – Type Into (or however you’re entering the officer code) “JRE” + counter.ToString.PadLeft(3,"0"c)
    – Check App State for Officer already exists
    — In appears, set OfficerExists true; Assign counter = counter + 1
    — In does not appear, set OfficerExists false

  • end Do While

I would also suggest setting a maximum value for the counter to avoid infinite loops in case of error. To do this just make the condition:

OfficerExists AND counter < maxCounterValue

Example of a direct increasing option

System.Text.RegularExpressions.Regex.Replace(YourJDEStringVar,"\d+$", Function (m) (CInt(m.Value)+1).toString.PadLeft(3,"0"c))

This worked!! Thank you for your help.

Perfect, so the topic can be closed
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.