RPA developer foundation training- Variable, Data Type and Control Flow- Practice 3- I am facing issue when I am trying to run a 'for each' loop by adding switch condition for an array

Problem Statement:
Considering a collection of error codes stored in an Array of Strings, separate them based on their type of error code (“Ax”, “Bx” or “Cx”) and store them in 3 different arrays.
Note: The initial Array should contain the following values:
“Ax001”,“Ax002”,“Ax003”,“Ax004”,“Ax005”,“Bx001”,“Bx002”,“Bx003”,“Cx001”,“Cx002”,“Cx003”,“Cx004”

What I did:
I created the workflow by creating an array with a given default value. Created for each loop, within which I added switch, by adding required conditions to segregate the error codes. I didn’t receive any compiler error, but whenever I try to run my program, it is showing only the default switch condition.
Using the write line I was able to get the array length, which is coming correctly. But for some reason when the loop is running it is not able to segregate the error codes.
Can someone help me to understand what I am doing wrong?
seperateErrorCodes.xaml (7.8 KB)

Hi
I tried to see your code but wasn’t able to see it
May be some issue with my studio
But
Hope these steps would help you resolve this
—as you said store this array of values in a array of string variable named arr_input using a Assign activity or even initialised in the variable panel itself as Default Value
arr_input = {“Ax001”,“Ax002”,“Ax003”,“Ax004”,“Ax005”,“Bx001”,“Bx002”,“Bx003”,“Cx001”,“Cx002”,“Cx003”,“Cx004”}

Then use a FOR EACH activity and pass the above variable as input and change the type argument as string in the property panel of for each loop

—inside the loop use a IF condition like this
item.ToString.Contains(“Ax”)
If true it will go to then part where use a ADD TO COLLECTIONS activity where in the item property mention as item.ToString and in Collections property mention as list_Ax
Where list_Bx is a variable of type System.Collections.Generic.List(of string) with default value as New List(of String) defined in the variable panel
Or
If the IF condition fails it will go to ELSE part where use another IF condition and mention like this
item.ToString.Contains(“Bx”)
If true it will go to THEN of this IF condition where again use a ADD TO COLLECTIONS activity where in the item property mention as item.ToString and in Collections property mention as list_Bx
Where list_Bx is a variable of type System.Collections.Generic.List(of string) with default value as New List(of String) defined in the variable panel
Or this If condition fails it will go to ELSE part where we can use a Final ADD TO COLLECTIONS activity
where in the item property mention as item.ToString and in Collections property mention as list_Cx
Where list_Cx is a variable of type System.Collections.Generic.List(of string) with default value as New List(of String) defined in the variable panel

Now we have got three separate list variables ready
But as we need them as a array variable to convert those three list variables to array use this assign activity with expression as mentioned

arr_Ax = list_Ax.ToArray()
arr_Bx = list_Bx.ToArray()
arr_Cx = list_Cx.ToArray()

Cheers

Hey Palaniyappan,
Thanks for sharing your inputs. I have tried it, but I am unable to print the result on the console. I tried log message and write line activities to print the list output, but I am getting ‘System.Collections.Generic.List`1[System.String]’ instead of value like Ax001 or Bx001.

What correction I should make?

Thank You,

Pragatee K

SeperateErrorCodesCorrected.xaml (7.92 KB)

You can try yourList(0) or String.Join(";",yourList)

PFB code which works properly:

Screenshot for variable declaration which will solve the issue: