Extracting A Specific Value From A Datatable

Good morning,

I have a datatable that consists of 2 columns and could contain a variable amount of rows and it is generated via a query to the database.

ColumnA ColumnB
01/01/2020 Healthcare Plan Changed
02/02/2020 Dental Plan Changed
03/03/2020 HSA Plan Changed

Now the number of rows in this datatable with a maximum of 6 total rows that contain 6 different things that could change in Column B.
My ultimate goal is to have UiPath look in the datatable for any of the keywords that occured (Dental Plan Changed, HSA Plan Changedā€¦etc) , and if any of of those rows exist, then bring back the associated date into a variable.

Below is the method that I am using, I would like to discuss a potential more efficient method with the community.

1-The Query generated my datatable

2- I place 6 consecutive IF statements that look for particular string in ColumnB using this formula. DATATABLE.AsEnumerable().Any(Function(x) x(ā€œCOLUMNBā€).ToString = ā€œHSA PLAN CHANGEDā€).

3- If the statement evaluates as true, meaning that the value exists in the datatable, I then get the datarow from the datatable using DATAROW= DATATABLE.Select(ā€œ[COLUMNB] = ā€˜HSA PLAN CHANGEDā€™ā€)(0).

4- After that I get the Index of that datarow in that table using DATATABLE.Rows.IndexOf(DATAROW)

5- After getting that datarow index, I then retrieve the date value corresponding to that datarow using Datatable.Rows(IndexVariable).Item(ā€œCOLUMNBā€).ToString

Is there a more efficient/elegant way of doing this?

Hi @BotAM97,

Have you tried using ā€œFilter Data Tableā€ Activity instead of if-statement? I attach my workflow here so you can run and see if this is something you can use.

I hope this helps. :slight_smile:

FilterTable.xaml (8.8 KB)

1 Like

Thank you @otico . This is a much more efficient and elegant solution.

1 Like

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