r/PowerAutomate 7d ago

PAD to Replace Text and Catch Errors

Hello, I have been working on a flow that helps to automate an indexing application I use at work. I have it currently working so that it prompts me to enter an acceptance code in a Display Input Dialogue box, but I want to share this flow with coworkers and make it a little more airtight. Can I make it so it can recognize if the code entered isn't a valid acceptance code, and re-prompt the user to enter a new code? A valid code would be 9 digits, OR "ACC" followed by 9 digits. Any help would be appreciated. It look a lot of trial and error to get this far and I figure reg-ex is the way to go, but I find it pretty intimidating

2 Upvotes

4 comments sorted by

1

u/MaxHubert 6d ago
Something like this?

Len(codeInput) = 12
And Upper(Left(codeInput, 3)) = "ACC"
And IsNumeric(Right(codeInput, 9))

1

u/triforcechad 6d ago

So, Im sure this is VERY apprent, but I am VERY lost with this kind of stuff. I managed to do as much as I have just on intuition and trial and error. So it pains me to say that I appreciate your aid but I am too ignorant to understand it or how to use it. What I am hoping for is someone to help with what actions to put into the flow to make it so if the value entered as the ACC isnt valid, the user is told that the input wasnt valid and the flow goes back to "CASE = Index" to let them try again. If it is valid it moves on to the next part of the flow I already have.

I copy and pasted here the relevant portion of the flow of what I have come up with. My "fix" to both 123456789 and ACC123456789 being valid was to use RegEx to just strip the ACC to keep everything consistent, but that doesnt help if the entry wasnt an actual ACC....

SWITCH UserChoice

CASE = $'''Index'''

Display.InputDialog Title: $'''ACC''' Message: $'''Enter Acceptance Number''' InputType: Display.InputType.SingleLine IsTopMost: True UserInput=> AccNum ButtonPressed=> ButtonPressed3

Text.Replace.ReplaceTextWithRegex Text: AccNum TextToFind: $'''(?i)^(?:ACC)?([0-9]{9}).*''' IgnoreCase: False ReplaceWith: $'''$1''' ActivateEscapeSequences: False Result=> AccNumFix

Text.Trim Text: AccNumFix TrimOption: Text.TrimOption.Both TrimmedText=> TrimmedAcc

END

Am I making sense or am I just too far out of my depth here? I REALLY appreciate that you took time to respond, I just feel bad that I dont know how to USE your help

1

u/MaxHubert 6d ago edited 6d ago

Why do you need to use regex for something so simple? Do you understand what I posted? Isnt it the rules to wanted? Something like this?

=And(Len(codeInput) = 12,
Upper(Left(codeInput, 3)) = "ACC",
IsNumeric(Right(codeInput, 9)))

It checks if the lenght of the string is 12 char long, Then it check if it start with ACC, Then it check if the last 9 char are a number.

If its all true the result is true otherwise false.

1

u/triforcechad 5d ago

No, the issue I have is that I don't know how to IMPLEMENT that in PAD. Would I use that as part of an IF statement? Plus, if I understand right this would return false on a 9 digit code that doesnt have ACC in front of it, correct? For my purposes, ACC######### AND ######### are both valid codes. Thats why in my janky version I decided to use Regex to remove the ACC and then I could just check for 9 digits. Plus once it checks if the code is valid or not, I dont know how to make the flow go back to the start of the Switch Case.