Using inequality functions in my conditional code


I am trying to write some conditions in my If activities on UiPath. I am reading data from a data table I am posting below.
Copy of TE YTD 2019.xlsx (14.0 KB)

One of the policies I am trying to write is"If the expense type = Hotel AND the city/location = Boston and the expense amount > 300

The code I am currently using to try to accomplish this is:

row(“Expense Type”).ToString.Equals(“Hotel”) And
(row(“City/Location”).ToString.Contains(“Boston”) And
Convert.ToDouble(row(“Expense Amount”).Replace.(“$”,“”))>300

I don’t need help with anything other than the actual conditional code.

Needless to say, it’s not working. Any suggestions?

Hello Christopher,

You had a few extra parens, but those shouldn’t cause any issue. The one real problem I noticed is that Expense Amount doesn’t belong in the example file you posted, I corrected the name. Also, you didn’t first convert the Expense Amount row to a string and so it didn’t know whether the Replace method existed for the object type.

Please see attached: Test_TEYTDInequality.xaml (5.7 KB)

Hi Derek,

Thank you for the great tip, my all accounts, it should work. I tried running the code in my workflow and I got the error"Input string was not in a correct format". The code I used in this is:

Row(“Expense Type”).ToString = “Hotel” And Row(“City/Location”).ToString = “Boston” And
Convert.ToDouble(Row(“Expense Amount (rpt)”).ToString.Replace(“$”, “”)) > 300

For the Then condition, I have an “Add Data Row” activity adding that violating line into a new Data Table. I am attaching my workflow here. The area which I have a question about is in the Main workflow.

The test is in activity “if 8.4”

ExpenseApproval.xaml (144.1 KB)
Copy of TE YTD 2019.xlsx (15.4 KB)
TestDT.xlsx (8.5 KB)

The file "Copy of TE TYD 2019 is my input file

The file “TestDT” is my output file.

Assign New datatable.“[Expense Type]=‘Hotel’ AND [City/Location]=‘Boston’ AND Convert([Expense Amount],‘System.Decimal’)>300”).CopyDataTable

above will store all sorted data into NewDataTable which you can use to create a new excel file.
Hope this will work for you!

Its more reliable zo use for String is … Compairisons the equal function.
E.g row(1).tostring.equals(“ABC”)

Hi Deepak,

The issue is, I already have a table being generated with the values that violate the rules. I don’t want to create another table that would just confuse the user.

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