Sometimes you may want to delete some column(s) in a data table based on a filter criteria. Perhaps, you want to delete all columns starting with “OLD_”. We can unleash the power of Groovy here. Let’s assume you have some data like this:
We’ve run the task using Run to Line (Ctrl+R) and then opened the Variables view from the Views toolbar. In the Variables view you can see all the variables currently in scope. $lastReturnValue just returns the value of the last step as the name suggest.
The Save Table Reference step saves the data from to a variable called people
Now to explain the formula which does the magic trick:
What we’re doing here is:
- Getting the table header using getHeader() method of ORQA table. It returns a list
- On that list we apply findAll method using a closure as the criteria - this is somewhat difficult to grasp so for further reference here is a post that explains it somewhat https://stackoverflow.com/questions/18136616/groovy-filter-criteria-on-findall-on-a-list. The criteria we’re applying returns all the entries in the list starting with “OLD_”
- Now we can join the list to get a comma separated list of the columns to remove.
Having stepped over the remove step, we can see the final result with the columns removed.