How to get row number from datatable based on search of a value

Hi friends,

i have a datatable which has invoices column.
i want to search invoice number and get its row index, invoice number in datatable don’t have leading zero but the problem is with invoice number which im going to search in datatable, some times it is 10409 and sometimes 00010409.

please help me to solve this.

Thanks in advance

@aslam_ali1

Dt.asenumerable.tolist.findindex(function(x) cint(x(“columnName”).tostring).equals(123) or cint(x(“columnName”).tostring).equals(123))

gives you the index

ColumnName is which you column you want to search

@aslam_ali1
You can try below LINQ

str_Invoice = "0123"
int_rowIDX = dt_InvoiceTable.Rows.Indexof((from rw in dt_InvoiceTable where CInt(rw("Invoice Number").ToString) = CInt(str_Invoice) select rw)(0))

Hi @aslam_ali1 ,
Thanks for reaching out to the UiPath community.

-Initialize a DataTable: Ensure you have a DataTable loaded with your data, including the “invoice_number” column.

  • Input Invoice Number: Prompt the user or set a variable to input the invoice number you want to search for. This can be a string.
  • Remove Leading Zeros: Use a custom VB.NET expression to remove leading zeros from the input invoice number. You can use the TrimStart function to achieve this.

invoiceNumber = invoiceNumber.TrimStart("0"c)
Then last step will be:

-Search for Invoice Number : Iterate through the DataTable rows to find the matching row(s) based on the input invoice number. Use a For Each Row activity to loop through the DataTable and compare the “invoice_number” column with the modified invoice number (without leading zeros). If a match is found, store the row index or perform any desired action. Replace your variable with the variable to store the row index, and customize the action to be taken when a matching row is found.

Regards,
@pratik.maskar

@aslam_ali1

Use lookup datatable activity and pass the search/lookup value as CInt(RequiredInvoice).ToString

The expression will ensure leading zeros are removed and lookup will give you the row index

Cheers

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