How to check only if first row contains required values in DT

Attached file contains data available in Data table.

I would like to check if ONLY First Row contains the “Customer Administrator or Customer Administrator F1 or Customer Administrator F2” text.

I have used If dt_ApproverFlowNames.Rows(0).ToString.Contains(“Customer Administrator”) or dt_ApproverFlowNames.Rows(0).ToString.Contains(“Customer Administrator F1”)…

but it is says the value is not available.

approver.xlsx (7.8 KB)

have used If dt_ApproverFlowNames.Rows(0).item(“columnName”).ToString.Contains(“Customer Administrator”) or dt_ApproverFlowNames.Rows(0).item(“ColumnName”).ToString.Contains(“Customer Administrator F1”)

or

create boolouput variable of type boolean and use condition as

booloutput=if(dt.Rows(0).Item(“App4”).ToString.trim.Contains(“Customer Administrator”) Or dt.Rows(0).Item(“App4”).ToString.trim.Contains(“Customer Administrator F1”),True,False)

Hope this Helps

@Sathish_Kumar_S

Ideally as all 3 start with same you can use as below…and if you need to check in all the columns then you need to use loop as well

  1. For loop with dt.Columns
  2. Inside loop use condition with dt.Row(0)("Currentitem.ColumnName).ToString.ToLower.Contains("customer adminstrator")
  3. On then side use a boolean variable and set it to true and after that use a break statement
  4. Outside the loop use if condition to check if the value is true then found else not…

Also if you need which column it is found in …you can save the index property of for loop as well before break or the column name

Or

simply use dt.Row(0).ItemArray.Any(function(x) x.ToLower.Contains("customer adminstartor")) - this returns true if ay cell in first row contains the required value else false

Hope this helps

Cheers

1 Like

I can’t specify the column name as “Customer Administrator” value will be under any column.

@Sathish_Kumar_S

Then use below code which gives you boolean output

dt.Row(0).ItemArray.Any(function(x) x.ToLower.Contains(“customer adminstartor”)

use any of the below code

Hope this helps

Getting below error

if(dt_ApproverFlowNames.Rows(0).ItemArray.Any(function(x) x.ToLower.Contains(“customer adminstartor”),True,False)

@Sathish_Kumar_S

no you can directly use it in the if Condition

1 Like

I am so sorry… it is going to else block

I have used below code in if statmet:

dt_ApproverFlowNames.Rows(0).ItemArray.Any(Function(f) f.ToString.trim.ToLower.Contains(“Customer Administrator”))=True

my bad… i have provided the wrong value to check… now it works

Hello @Sathish_Kumar_S ,

You can use the below expression to check the given value is exists in the first column.

Expression : TestDT.Rows(0).ItemArray.Contains(“Customer Administrator”) Or TestDT.Rows(0).ItemArray.Contains(“Customer Administrator F1”) Or TestDT.Rows(0).ItemArray.Contains(“Customer Administrator F2”)

Result :
image

Workflow details :

  1. Use read range to read the data and store in a Data Table variable (TestDT)
  2. Use an assign activity (or If condition as per your need)
    (Boolean variable) Found = TestDT.Rows(0).ItemArray.Contains(“Customer Administrator”) Or TestDT.Rows(0).ItemArray.Contains(“Customer Administrator F1”) Or TestDT.Rows(0).ItemArray.Contains(“Customer Administrator F2”)

Regards,
Rohith

Thank you very much for your support during weekend

1 Like

@Sathish_Kumar_S

hope you got the solution right

cheers and Thanks

happy automation

1 Like

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