I’d like to add a check before the cmd searching if “Column3_Arr1” exist. If exist the node should be follow the setting already present otherwise have to create the column “Column3_Arr1” filled by all -10 values and then follow the cmd out_New_CLASS = “Not_subs”.
Could someone suggest the right correction to the script?
The first example you mentioned is something that I already try, but the java snippet node configured as in the example doesn’t work and I really don’t understand why.
The saw also the second solution, but I have a doubt because in the example the column to look for is use in the input file, but if this is missing how it can be use as input? Strange.
Hi @tommasopalomba , as an addendum to @mlauber71 's solution, you cannot directly access the value of Column3_Arr1 if there is a chance it won’t exist because that would then result in a configuration error.
Instead, to access the contents of your column which might exist, could write something like this:
This does not result in an error because Column3_Arr1 is referenced only via a call to the getCell function rather than directly through a variable name. The getCell function returns a run-time exception which can be trapped, rather than a compilation/config error which cannot.
Note that you cannot, within a single java snippet optionally choose to create a new column, so you would need to have a flow containing additional nodes to perform actions such as creating new columns, as @mlauber71’s flow indicates.
With the new Array-type variables which I think have happened since this original question, along with the new-ish @VernalisConfigurable IF/CASE... nodes, it is possible to do this with no scripting requirements:
The Extract Column Header / GroupBy / Table Row to Variable sequence puts the column names into an array variable, and then the Configurable IF/CASE Switch (Flow Variable Value) node can test various options for members of the array, including the selected Any Equals option for an exact match: