Hello friends i have a table which has invoice number 123, 123-1, 123-2, 123-3. First thing i have to do is to check whether 123 is present, if i just filter using 123 it just gives value 123 row index. I also want to know the last value that is 123-3 or any other number after - so that i can add next number and make it as i want, how to get filter the last value and add next value as 123-4.
Read the table data and store it in a DataTable variable, let’s call it “dataTable”.
Use the Select method of the DataTable to filter the rows based on the pattern “123” in the invoice number column. This will give you an array of DataRow objects that match the filter condition.
makefileCopy code
filteredRows = dataTable.Select("InvoiceNumber LIKE '123%'")
To get the last value in the filtered rows, you can use LINQ to sort the rows based on the invoice number column in descending order and retrieve the first row.
The above code assumes that the last value is always in the format “123-X” where X is a numeric value after the hyphen.
5. You can then use the “nextInvoiceNumber” value as needed, such as adding it to a new row or performing any other operations.
Use a do while loop with condition as true and in the properties assign a variable indexvar of type integer to the index property,also for safety add a max iteration
Use find/replace activity with foundcell as output variable and value to search for as the inv number 123-(indexvar+1).ToString
Use if with Not (IsNothing(Foundcell) OrElse String.IsNullOrEmpty(FoundCell)) and on then side use assign with foundindex = indexvar+1 also another assign to save the foundcellvar = foundcell and on else side add break
Now after the loop you have the last index where it is found and the last cell number as well…first check using if …if the foundindex value is >0 only then it is found
Now use insert row activity and use the foundindex to insert a row
After that use write cell and use foundcell and add the value needed.make sure to increment the number by 1 system.Text.RegularExpressions.Regex.Match(foundcellsvar,"\D+").Value + (Cint(system.Text.RegularExpressions.Regex.Match(foundcellsvar,"\d+").Value)+1).ToString
@raja.arslankhan
Thanks you so muchhhhhhhh
It was a wonderful solution. thanks a lot man.
to get the exact o/p what i needed i used below code for last line which you mentioned in step4.
nextInvoiceNumber=lastInvoiceNumber.Split(“-“c)(0).ToString+”-”+(Integer.Parse(lastInvoiceNumber.Split("-"c)(1)) + 1).ToString()
because from that code i was getting o/p as 123-3-4