I have a range from a original datatable (dt_Orig) which I filter based on a given ID, e.g. via the variable str_ID. By filtering the filtered datatable (dt_OrigFiltered) is created.
I have to process all rows in dt_OrigFiltered whereby the original cell references in dt_Orig should be retained because I have to write back values in dt_Orig.
Problem in the code: The index for the original cell reference (int_OrigRowIndex) is for the first Row item in dt_OrigFiltered always -1 and does also not change in case of more than 1 Row items within the ForEach Loop which cause the error that the assigning in the dt_Orig cannot be processed with index -1 and only the first Row item will be written back.
Do you know what is wrong in the Assign activity for int_OrigRowIndex?
or
how I can process the dt_OrigFiltered in another way whereby the original cell references in dt_Orig are retained?
as two datatables are different it might not identify…Also as all the rows have same data also it is difficult with only values as well
in this case better to first add a column index and use another loop before filtering and in loop just assign index or row number to each column currentrow("Index") = currentindex.now index will have row numberof each row whcih you can use in further loop
First, the additional column „Index“ should be added to the existing datatable dt_Orig, for example in the beginning as first column via activity AddColumnToDataTable?
Second, loop through dt_Orig and assign the row index to column „index“ - how do you recognize the value of currentindex? Is currentindex a variable, if yes which type?
Once all rows in dt_Origin are assigned with row index in column „index“, the datatable can be filtered to dt_OriginFiltered.
Then loop through dt_OroginFiltered for processing and write the value back directly in dt_Origin (correct?) with identifier from column „index“
Is it necessary, to delete after looping the column „index“ as it is a help column?
Hi @stefi
You can use dt_Orig.DefaultView.RowFilter it will create a temporal filtered table but keeping the original indexes; so you don’t need to create a 2nd dt variable
Assign ‘Filter dt with given ID’
dt_Orig.DefaultView.RowFilter "ID = " & str_ID
The following assign will convert the filtered rows in your second dt. However, this could be optional as you can directly interact with dt_Orig.DefaultView.ToTable.Rows in the foreach
Assign ‘Table keeping original indexes’
dt_OrigFiltered = dt_Orig.DefaultView.ToTable
Hi sudster,
Thank you for your reply. There are many requirements which I not mentioned here as it would be too much and does not have something to do with the initial problem.
I have now a solution for it. Thank you very much anyway!
Thank you very much for your answer. This is a really charming solution due to its brevity. Unfortunately, it does not completely work in my case because always the first item was assigned in the dt_Orig and sometimes it must not be assigned the first item…
I have a solution now. Thank you very much anyway!
@Anil_G
I have an additional question to your solution.
Do you have an idea how I can add following logic into the solution:
If the ID-groups have more than 1 group-item (e.g. ID = 1 with in total 3 items, see screenshot on the top), how can I create an indeces list with the reference to the dt_Origin?
In some cases I need the range of the concerned ID items in order to write back the same info (that is only known after the last item has been processed) to all ID items in some excel.