Search for value in datatable with complex logic

Hello!

I’m facing a tricky challenge with searching for a value in a datatable.

The datatable data is fetched from a website drop-down menu, using Find Children and Get Attribute within a for each which adds rows to datatable, containing numbers and number ranges e.g:
32000-32005
32006
32008-32010
32012
32014-32015
…and so on, about 500 entries or more.

I receive a specific 5 digit number from a queueitem and need to select either the matching range or number, e.g:
Queueitem number is 32001 then range 32000-32005 should be selected or if queueitem number is 32006 then select 32006.

When the correct row is found then it needs to be selected in the drop-down menu.

I struggle with how the logic for such a search function would look like and/or if I should filter the results in different steps.

Or should I abondon the datatable activit for another way to select the appropriate value in the drop-down menu?

I tried a “Type into” activite but it doesn’t work as sometimes you get the first matching value of the 4th number and it will select the wrong range as the last 5th number is not showing in the list.

Any ideas is much appreciated!

@andreas.wik

can you try with below logic,
After getting queue item

  1. first check that queueitem was available or not in extracted data from drop down
    2.If yes, click and go with that flow
  2. if not, loop range values based on syntax(make decision based on ‘-’) split those values
    3200 - 3205 make it as 3200 and 3205 now write a condition your queueitem >= 3200 and queueitem <= 3205 if this condition satisfied then you can proceed with other steps


try this logic and let me know
and make sure your queueitem should be int if not convert it

happy automation

can be done also different more direct, but is another topic

we assume the following result:

and can do the filtering within a single Assign activity with a LINQ

Variables:

dynamize searchKey with your needed Number String
searchKey = CInt(myQueueItemNumberString)

Filtering:


strSelect =

( From d In dtOptions.AsEnumerable
Let t = d("Options").toString.Trim
Let tsp = t.Split("-"c)
Let ptsp = tsp.Select(Function (x) CInt(x)).toArray
Let arrMinMax = If(ptsp.Length=1, {ptsp(0),ptsp(0)}, ptsp)
Where searchKey >= arrMinMax(0)
Where searchKey <= arrMinMax(1)
Select s = t).FirstOrDefault()

if the value is found in any entry (range or direct number) we get back the option select string like:
grafik
for: “32009”

If the value is not found, then we get back null, which we can test with
isNothing(strSelectText)

1 Like

Thank you @ppr that worked wonders!

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