pentaho/pentaho-kettle · error · KettleStepException
ScriptValuesMetaMod.Exception.FieldToReplaceNotFound
ScriptValuesMetaMod.Exception.FieldToReplaceNotFound
Error message
ScriptValuesMetaMod.Exception.FieldToReplaceNotFound
What it means
Thrown in Script.addValues when a field is marked for replacement but cannot be found in the incoming row's row metadata AND the configured fieldname is empty. The step indexes each replace-target field by looking it up in rowMeta; a negative index means the field does not exist on the input row. This first throw site fires specifically when meta.getFieldname()[i] is empty while replace is enabled.
Solutions
- Open the Modified Java Script Value / Script step and fill in a non-empty Fieldname for every row where Replace is checked.
- Uncheck the Replace option for result fields that are new (not replacing an existing input field).
- Ensure an upstream step actually produces the field named in the Fieldname column (or the Rename column).
- Re-edit and re-save the step metadata if it was migrated from an older version.
Example fix
// before (metadata): replace=true, fieldname="" // after (metadata): either fieldname="myField" with replace=true, // or replace=false for a newly created output field
Defensive patterns
Strategy: validation
Validate before calling
// before running, for each script field row:
for (int i = 0; i < meta.getFieldname().length; i++) {
if (meta.getReplace()[i] && Utils.isEmpty(meta.getFieldname()[i])) {
throw new IllegalStateException("Replace checked but Fieldname empty at row " + i);
}
} Try / catch
try {
step.processRow();
} catch (KettleStepException e) {
if (e.getMessage().contains("FieldToReplaceNotFound")) {
logError("Fix the script step fields grid: " + e.getMessage());
} else { throw e; }
} Prevention
- Never check Replace without also filling in Fieldname.
- Preview upstream rows to confirm the field exists before enabling Replace.
- Re-validate step metadata after migrating transformations between versions.
- Use the step's fields-sync feature to keep the grid aligned with the input layout.
When it happens
Trigger: In addValues (called from processRow) for each i where meta.getReplace()[i] is true: rowMeta.indexOfValue(meta.getFieldname()[i]) returns < 0 and Utils.isEmpty(meta.getFieldname()[i]) is true — i.e. replace is checked for a field slot with no field name configured.
Common situations: A user enabled 'replace value' on a script result row but left the Fieldname column blank; step metadata edited/renamed upstream so the saved field mapping no longer matches the row layout; copying step config between transformations with different input fields.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- AutoDoc.Exception.FilenameFieldNotFound
- AutoDoc.Exception.FileTypeFieldNotFound
- DynamicSQLRow.Exception.FieldNotFound
- GetTableNames.Exception.CouldnotFindField
- HTTP.Exception.CouldnotFindField
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/f483044721b493c4.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java:149
// What is the output row looking like?
//
data.outputRowMeta = getInputRowMeta().clone();
meta.getFields( getTransMeta().getBowl(), data.outputRowMeta, getStepname(), null, null, this, repository,
metaStore );
// Determine the indexes of the fields used!
//
determineUsedFields( rowMeta );
// Get the indexes of the replaced fields...
//
data.replaceIndex = new int[ meta.getFieldname().length ];
for ( int i = 0; i < meta.getFieldname().length; i++ ) {
if ( meta.getReplace()[ i ] ) {
data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getFieldname()[ i ] );
if ( data.replaceIndex[ i ] < 0 ) {
if ( Utils.isEmpty( meta.getFieldname()[ i ] ) ) {
throw new KettleStepException( BaseMessages.getString(
PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getFieldname()[ i ] ) );
}
data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getRename()[ i ] );
if ( data.replaceIndex[ i ] < 0 ) {
throw new KettleStepException( BaseMessages.getString(
PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getRename()[ i ] ) );
}
}
} else {
data.replaceIndex[ i ] = -1;
}
}
data.cx = ScriptMeta.createNewScriptEngine( getStepname() );
data.scope = data.cx.getBindings( ScriptContext.ENGINE_SCOPE );
bFirstRun = true;
View on GitHub (pinned to f3058517a1)