In a workflow I extract some Data and an ID which I want to save locally.
The ID-name needs to be the file name, but in case that the ID/file-name already exists ( for example ID = 123ABC1, last number is a digit), I want to save it as ID = 123ABC2.
The robot checks again, if that ID already exists in the filepath, if yes it chooses ID = 123ABC3 etc.
It´s adding up +1 for each loop if the name already exists.
Anyone has an idea how to solve that?
Thanks a lot!
@evangemert thanks a lot!
looks good so far.
But is there also a way that I count up from 0/nothing to 1?
If I use ID = 123ABC1, I get 123ABC2, but If I have 123ABC, I get the error "Assign : Input string was not in a correct format.
True, it only works when the last number is a digit, from your question I understood that that is the case. If it’s not the case you’ll need to build in an extra check. You can go about that several ways, but I like using regular expressions. You’d need to add the following to the true part of the if activity:
If activity with System.Text.RegularExpressions.Regex.IsMatch(ID, “\d$”) (this checks if the last character of the string is a digit)
Add the 3 assign activities you already have to the True part and add another assign activity to the False part: ID = ID + “1”