Check if datatable contains some values and returns true or false?

Hi,

Is there any way to check a datatable if it contains some values… and if it does it returns true.

I want to use it on do while loop.

Thanks

yes of course
in for each row loop use a if condition like
row(“yourcolumnname”).tostring.contains(“yourstring”)
we can mention this even in a loop we want like in while loop
pass this as condition in if activity
outdt.Rows(rowindex)(columnindex).ToString.Contains(“yourvalue”)

Cheers @mz3bel

6 Likes

Thanks @Palaniyappan

Not a row, the whole datatable, something like this

Not extracted.Contains(" [DATAS] = ‘DATA’ ") (NOT REAL)

ps : Just an example

1 Like

Fine
in that case
–convert a datatable to a string using output datatable activity and pass the input as datatable and get the output as a string named out_text
–now use a condition like out_text.ToString.Contains(“yourvalue”)

simple isnt it

Cheers @mz3bel

6 Likes

Did that work to check the string
Cheers @mz3bel

1 Like

@Palaniyappan

Not yet, still trying… give me a minute please

Fantastic
Cheers @mz3bel

1 Like

@Palaniyappan

I did this :

extractedAlarms.ToString.Contains(" [DATA] = ‘40100’ OR [DATA] = ‘30800’ OR [DATA] = ‘7800’ OR [DATA] = ‘7900’ OR [DATA] = ‘7900’ OR [DATA] = ‘40101’ OR [DATA] = ‘30000’ OR [DATA] = ‘1600’ OR [DATA] = ‘30200’ OR [DATA] = ‘40102’ ").ToString

But return false, which it shouldn’t…

is this is a string in that text @mz3bel
[DATA] = ‘40100’ OR [DATA] = ‘30800’ OR [DATA] = ‘7800’ OR [DATA] = ‘7900’ OR [DATA] = ‘7900’ OR [DATA] = ‘40101’ OR [DATA] = ‘30000’ OR [DATA] = ‘1600’ OR [DATA] = ‘30200’ OR [DATA] = ‘40102’

1 Like

extratctAlarms is a datatable

[DATA] = ‘40100’ OR [DATA] = ‘30800’ OR [DATA] = ‘7800’ OR [DATA] = ‘7900’ OR [DATA] = ‘7900’ OR [DATA] = ‘40101’ OR [DATA] = ‘30000’ OR [DATA] = ‘1600’ OR [DATA] = ‘30200’ OR [DATA] = ‘40102’

Data inside the datatable, which i need to find if i want to continue the process.

Fine
do You mean DATA is a column
Cheers

1 Like

No as datatable type, like a table

extractedAlarms (assing) extractedAlarms.Select(" [DATA] = ‘40100’ OR [DATA] = ‘30800’ OR [DATA] = ‘7800’ OR [DATA] = ‘7900’ OR [DATA] = ‘7900’ OR [DATA] = ‘40101’ OR [DATA] = ‘30000’ OR [DATA] = ‘1600’ OR [DATA] = ‘30200’ OR [DATA] = ‘40102’ ").CopyToDataTable()

I did this once, to select only that data…

this should be a columnname buddy
thats why i asked whether its a column name or not
how we want to filter and look for condition now
Kindly elaborate a bit more pls
Cheers @mz3bel

1 Like

Yes yes sorry that’s a column name, didn’t unterstand you at first.

Ok, my data has like 38k rows… my robot can only process like 1k of that data, all the rest, can’t be done by a robot for now.

So from a web table, which shows that data, i use extract data activity… and process it with the robot. But sometimes i don’t find the data needed. So the robot crashes. This is why i want to put a while loop so he can keep looking untel he get the data needed.

The data stored on the web changes every 30 secondes…

I used select with the column so i can filter the data i can process, now i want to use that same idea to loop untel he gets the data…

I need something like this :

extractedAlarms.Contains(" [DATA] = ‘40100’ OR [DATA] = ‘30800’ OR [DATA] = ‘7800’ OR [DATA] = ‘7900’ OR [DATA] = ‘7900’ OR [DATA] = ‘40101’ OR [DATA] = ‘30000’ OR [DATA] = ‘1600’ OR [DATA] = ‘30200’ OR [DATA] = ‘40102’ ") = True or False?

There’s an activity that’s already available for this. Take a look at Lookup Data Table. It will check whether a value exists within a column and return -1 if not present otherwise give the index at which the first instance is present.

2 Likes

Thank you @dmccammond, can you please tell me how does it works?

Because i looked on internet, but couldn’t unterstand how.

@Palaniyappan

Hi, how can i use this activity for my issue please?

1 Like

lets do one thing, in a very simple way
keep all these values
{“40100”,“30800”,“7800”,“7900”,“7900”,“40101”,“30000”,“1600”,“30200”,“40102”}
is a string array named str_array
then
–use a for each row loop and pass the datatable variable as input
–inside the loop use a if condition like
str_array.Contains(row(“yourcolumnname”).ToString)
if the above condition satisifies it will go to THEN part of if condition where we can mention like a write line activity
"the column has the value "+row(“yourcolumnname”).ToString

hope this would help you
Cheers @mz3bel

2 Likes