I’m currently doing an exercise where I build an automation with a data table. This automation is meant to look at each row in the data table and input information into an application. The tricky part is all activities where ColumnA=“A” need to be done first, then all activities where ColumnA=“B”, and again where ColumnA=“C.”
After sorting the data table by ColumnA, I added a Switch activity with the expression:
row.item(“ColumnA”).ToString
Then I created three cases with A, B and C. Inside each one I added a For Each Row activity. However, I found when running the automation that the Case A was going through ALL rows instead of just the rows where ColumnA=“A”. How do I make sure this doesn’t happen?
Did you add a for each row activity inside the switch cases? If yes, you would need to reverse that logic. Put the Switch activity inside the For Each Row activity.
And regarding the quotes, that is correct; you do not want quotes surrounding the letters in the case parameter.
I initially had a Switch activity inside the For Each Row, like you suggested, but I found that it was not doing the activities in the correct order. For each Case, the browser URL is different and it requires a login. After each case is completed, I wanted to close the browser so I don’t end up with 50 open windows.
To provide some context here are the activities inside each Case:
Attach Browser
Open Browser
Login
For Each Row (with Get Row Item and Type into activities)
Close Browser
By having a Switch inside the For Each Row, it makes the automation less efficient (i.e. logging in and off 50 times for 50 rows, instead of logging in 3 times for each case).
This is why I decided to change it and have a For Each Row inside the Switch activity. However, when I tried to run the automation and it got to the “For Each Row” activity inside Case A, it was pulling every single row instead of just rows where Column=A.
Got it. I think a better plan would be to use the filter data table activity into a temporary datatable, and iterate through that. See the attached .xaml for guidance. It’s filtering the table 3 times, one for each letter. Then you can use the switch for any activities unique to the particular letter
You’re welcome! Also I just realized the expression in the switch could have just been ‘letter’ instead of ‘CurrentRow(“Column A”).toString’. Either will work though!
Also would appreciate if you could mark my comment as the solution. Happy bot building!
Open the browser window first, and store it in a variable. Then in your Cases you attach to that browser variable and use Navigate To to send that browser window to the URL you want.
If you are using the workflow provided by @Greg_Jacobson, you’ll likely want to change “row” to “letter”. “row”, or some form of that, is a default variable used inside of a for each loop for each iteration. The activity given to you used the variable “letter” instead. So try using letter.item(“ColumnA”).ToString instead.
That’s okay. The word is unimportant, except for consistency sake. If you want to change it back to “row” though, in the for each loop, just change the word “letter” to “row”. I’ll highlight the spot below.
That is what I did.
I realized that I had to change the TypeArgument of For Each to String. However, once I did that, the error on the Switch expression changed to “item is not a member of string.”
Thank you! The validation errors are solved but the browser is still closing after each row, which is not what I want. I want the browser to close after each case is completed.