If statement is not outputting what it should

Hi Everyone.

I have a flow that is scraping data from the target website and creates a data table. I want to run a for each row in the data table, if the price is less than 300, then it will write to an excel that says cheap products. otherwise it will write to an excel that says expensive products. my automation is flowing but nothing is outputting. What do I need to do with my condition building differently?

Below is a screenshot of the flow.

@hxz171330

Price is a column in datatable I believe…

So you need to use cdbl(currentrow("Pricecolumnname").ToString.Trim) > 300

If the price value contains any special characters like $ or so we need to hndle them

Currently what you are doing is just to create a variable of type integer and when no value is given the value will be 0 and always gets compared with same

Cheers

Hi,

Yes Price is a column in the datatable. Would I create a variable using what you wrote? Or would I write that down in the condition VB expression for the if statement?

When i input that into the vb expression, the flow still runs, but again I get no excel file created for either cheap or expensive products.

This is what the extracted data looks like. the Price column is set for numbers instead of string so there should be no dollar sign when parsed.


Processing: image.png…

@hxz171330,

You should be using if condition like this.

CurrentRow.Item("Price") < 300

I run into this error when I do just that with the condition statement

@hxz171330,

This should work.

CDbl(CurrentRow.Item("Price").ToString.Replace("$"c,"")) < 300
1 Like

It runs, but there is still no excel output. It should be checking in each row for the price of the item that it is below 300. if it is, it should write that row to the excel file. If it is above 300, it should write to a different excel file. Nothing is being executed though. After the data scraping, it says the execution is finished so I am not sure why it is not writing anything to the excel.


Processing: image.png…

Hey @hxz171330

You have to change some logic in your code first of all, take two assign activity above for each row in datatable activity, create two new datatable variable dt_ProductsUnderprice and dt_ProductsOverprice, assign them the structure of extracted table using Clone Method.

In If Activity Condition:

CDbl(CurrentRow.Item("Price").ToString.Trim.Replace("$"c,"")) < 300

Put Add Data Row Activity in both section Then and Else, as mentioned in below image.

At the end outside foreach row activity take two write range activities, and pass those two data table variables in them.
Note. Select Add Header Property.

You will get a excel file with two different sheets.

Screenshot for your reference!

Here is the .xaml file for your reference!
Dowload this .xaml at your project folder location then open it.
ExtractProductData.xaml (11.6 KB)

Note: In this .xaml, activities are after your extracted data activity.

Happy Automation!

Best regards,
Ajay Msihra

Thank you! That worked!

1 Like

@hxz171330 Great to hear that, I request you to mark the above post as Solution.
So, that it will help others to find correct solution.

Happy Automation!

Best regards,
Ajay Mishra

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.