For Each Row only when Column="text"

Hi all!

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?

Thank you so much for your help!

Post screenshots of your code. Do you have double quotes around the A B and C cases?

I don’t have any quotes around the A, C and C cases - is that correct?

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.

It should look like the attached.Sand.xaml (6.8 KB)

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:

  1. Attach Browser
  2. Open Browser
  3. Login
  4. For Each Row (with Get Row Item and Type into activities)
  5. 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

Sand.xaml (8.6 KB)

2 Likes

Thank you so much! That is a great idea! I’m trying that now.

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!

HI Greg - after creating the Switch activity and using row.item(“ColumnA”).ToString I’m getting an error message stating ‘row’ is not declared.

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.

@sidb

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.

I don’t want it to be a letter necessarily, the column value will be a text.

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.

image

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.”

That won’t work, you don’t want to refer to letter as row, as it is not a row object. It is a row value.

@sidb, my solution referred to the row as CurrentRow, so you would need to remain consistent when referring to the row item

Don’t forget the .ToString

Try changing the type on the switch activity too. Its may be a different type right now. Change to string, and see if that clears it.

Did you set the Switch to 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.