I am a new learner. I came up with a simple task and I cant solve it.
I have a list of some numbers: (Ai123, Ai243, Bi344, Bi3443, Ci24244, Ci48484). Lets say that these numbers are some kind of invoice numbers. And I would like to solve my issue with “If and for each”.
I would like you to sort these invoices from my list into 3 separate lists (starting with Ai, Bi and Ci) and add each invoice accordingly to one of the three new lists.
I started by creating an “InvoiceList” with assign: InvoiceList = New list (of String) From {“Ai123”, “Ai243”, “Bi344”, “Bi3443”, “Ci24244”, “Ci48484”} and then created 3 empty lists with assign: AInvoiceList, BinvoiceList and CinvoiceList
Then I create a “for each loop” to loop through each item (invoice) in the InvoiceList.
In the body of the loop I put IF “item.ToString.StartsWith (” Ai “)”
For “then” I added in the sequence “Add to Collection” and there it adds each item that meets the condition to the AInvoiceList. In “Else” I threw a second IF that checks if item.ToString.StartsWith (“Bi”) if so, then “Add to Collection” and adds an item that meets the BinvoiceList condition, and in “Else” - “Add to Collection” and items are flying to CinvoiceList
I think everything is correct, are you getting any errors while running, please share those error log messages,
one more thing in the assign use “New List(Of String)” in all the statements, I saw in some you have written “New list (of String)” it may give errors(validation errors) in some situations
Also there is a simpler way to do this. You don’t even need the Ifs. In your Add to Collection activity, where you tell it the collection to add to, just do:
left(item,2) + “Collection”
This will give you AiCollection, BiCollection etc depending upon the first two letters of the item.
Maybe it works but I have no idea how to write down all three lists to see them in my output. Moreover in my output I have letter “y” and I dont know why.
Regarding “y” It was my mistake. I have an additonal Log Message.
Use Debug instead of Run. Then right-click your activities and set breakpoints. It’ll pause at each breakpoint and then you can look at the debug panels on the left to see the realtime values of each variable/list.