Going through a list of orders and do specific things based on value in another column

Here’s my sample data:

SKU Quantity PricePaid MarketPlaceOrderID Flag
Garden item 1 21.57 #66164 ShopA
Home item 1 21.57 #66164 ShopA
Shed item 1 18.36 #66170 ShopD

Which has been copied to a Data Table and then:

For Each row in dtData
Assign: varOrderID = row(“MarketPlaceOrderID”).ToString.Trim()
(variable declared ‘varPreviousOrderID’ which starts blank)

IF varOrderID = varPreviousOrderID Then:

Assign: varFlag = row(“Flag”).ToString.Trim()

Message Box "Same OrderID! " + varOrderID + varPreviousOrderID


Message Box: Different order ID as before

Assign: varPreviousOrderID = varOrderID

So what this Flow does is it goes through an order sheet, if it’s a new order then it does one thing and if it’s the same order as the previous line in the Data Table, then it does another thing.

Works perfectly. But I need to drill it down further in the sense that in the sample data there is a Flag column. So…

When it goes through Order #66164 it will be able to do one set of actions for line 1 (Garden item) and another set of actions for line 2 (Home item)

Where I’m at currently is when it does line one, it shows a Message Box with the Flag variable, but if there’s 3 lines of data, it shows the message box 3 times.
when it gets to line 2, it will show the correct Flag but then show it 3 times.
when it gets to line 3, it will show the correct flag but then show it 3 times.

Hopefully this has explained it well and any help is much appreciated.

You don’t need to do things like this. There’s no need for that extra variable. Just do:

If row(“MarketPlaceOrderID”).ToString.Trim = varPreviousOrderID

Just a tip.

What I would do is put this in my For Each Row property:


Now it will just loop through the unique order IDs. Then the first step in the For Each Row is a Filter DataTable that gets all the rows from dt_Orders that matches CurrentRow(“MarketPlaceOrderID”). Now you have a cohesive set of data just for the one order and can process them as a unit. Now you don’t need all this “is it the same order as the last one” logic.

Thank you :slight_smile:
The issue im facing though is in relation to the Flag in the sense I need to somehow put in memory(i.e a variable) the flag of whatever line the row is on.

The only problem is, it does this but adds it 3 times. i.e. if I choose to display the variable in a message box, it shows it 3 times.

The reason being for this is I want to then do specific things based on the flag reference.

hmmm just had an idea, maybe a Get Row item

Use the Get Row item worked in the end. Essentially when im going through each line, as well as identifying if an order id is duplicated, I needed to know what the flag was on whichever line it was using.
Get Row item did this for me.

As I said, this “is the order number the same as the last one” logic is what’s fouling things up. If you just use my suggestion to loop through unique order numbers and process all rows just for that order, the need for that logic - and these issues - goes away. What happens with your logic if the orders aren’t all grouped together in order in the source? My method makes that irrelevant.

Thank you for your suggestion re. row(“MarketPlaceOrderID”).ToString.Trim = varPreviousOrderID - works great.

Appreciate your other idea too and it makes perfect sense. What you’re saying is based on the OrderID, filter the Data Table so it only shows things pertaining to that OrderID and then go from there?

Sound idea and makes it more robust if the Order ID’s go out of synch like you say.

But how do i Filter the Data Table like you say

after changing my IF to what you advised, i do get this error unfortunately:

Hi @steve1977beyond

The error looks like you are copying the code and paste it. Ensure the double quotes are of type " and not inverted.

1 Like

No quite.

  • For Each Row in Data Table: dtOrders.DefaultView.ToTable(True,“MarketPlaceOrderId”)
    ** Filter Data Table dtOrders into dtCurrentOrder; set filter to “MarketPlaceOrderId” = CurrentRow(“MarketPlaceOrderId”).ToString
    ** For Each Row in Data Table: dtCurrentOrder (make sure to change it from CurrentRow to something like CurrentOrder so that it doesn’t conflict with the CurrentRow in the original For Each)
    *** process the items in the order using CurrentOrder(“columname”).ToString to get the values

The first For Each row loops through only the unique MarketPlaceOrderId values. The Filter Datatable then gives you a new datatable (dtCurrentOrder) of all the rows for one MarketPlaceOrderId which you can then loop through and process.

1 Like