You can use the Parameters table to avoid using hard-coded string values, such as field names (customer for example).
Another example is in the User Defined Java Class - Calculate the date of Easter.ktr sample transformation, which is in the
data-integration/samples/transformations directory. That sample KTR has a parameter called YEAR. The YEAR parameter is referenced with the getParameter()method, as shown in the following example:
getParameter("YEAR")
At runtime, it will return the year String value.
Class Member Variables and the getVariable Function
When getting parameters that point to transformation parameters, the User Defined Java Class step behaves differently depending on when
the getVariable function is called. If it is in the init()
method, the parameters behave as expected. If the initialization is on a class member
variable, the variable is not resolved by design, as shown in the following
example:
private final String par = getVariable("somePar"); // DOES NOT resolve correctly private String par2 = null; public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { logBasic("Parameter value="+par+"\[MEMBER INIT\]"); logBasic("Parameter value="+par2+"\[INIT FUNCTION\]"); setOutputDone(); return false; } public boolean init(StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface) { par2 = getVariable("somePar"); // WORKS FINE return parent.initImpl(stepMetaInterface, stepDataInterface); }