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?
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.
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.
@hall1570
simple.
Assign New datatable.
newDataTable=yourExcelReadDt.select(“[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!
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.