{"record":{"id":"bf38e89617376f4c","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmetamod-exception-fieldtoreplacenotfound-bf38e8","errorCode":null,"errorMessage":"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound","messagePattern":"ScriptValuesMetaMod\\.Exception\\.FieldToReplaceNotFound","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMetaMod.java","lineNumber":406,"sourceCode":"    optimizationLevel = OPTIMIZATION_LEVEL_DEFAULT;\n  }\n\n  @Override\n  public void getFields( Bowl bowl, RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,\n    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {\n    try {\n      for ( int i = 0; i < fieldname.length; i++ ) {\n        if ( !Utils.isEmpty( fieldname[i] ) ) {\n          int valueIndex = -1;\n          ValueMetaInterface v;\n          if ( replace[i] ) {\n            valueIndex = row.indexOfValue( fieldname[i] );\n            if ( valueIndex < 0 ) {\n              // The field was not found using the \"name\" field\n              if ( Utils.isEmpty( rename[i] ) ) {\n                // There is no \"rename\" field to try; Therefore we cannot find the\n                // field to replace\n                throw new KettleStepException( BaseMessages.getString(\n                  PKG, \"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound\", fieldname[i] ) );\n              } else {\n                // Lookup the field to replace using the \"rename\" field\n                valueIndex = row.indexOfValue( rename[i] );\n                if ( valueIndex < 0 ) {\n                  // The field was not found using the \"rename\" field\"; Therefore\n                  // we cannot find the field to replace\n                  //\n                  throw new KettleStepException( BaseMessages.getString(\n                    PKG, \"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound\", rename[i] ) );\n                }\n              }\n            }\n\n            // Change the data type to match what's specified...\n            //\n            ValueMetaInterface source = row.getValueMeta( valueIndex );\n            v = ValueMetaFactory.cloneValueMeta( source, type[i] );","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMetaMod.java#L388-L424","documentation":"During getFields() row-metadata calculation, the step looks up each configured fieldname[i] in the input row. When the field is absent AND no rename[i] is configured, it throws KettleStepException 'FieldToReplaceNotFound' naming the field, because there is no field to apply the script's replace/type change to.","triggerScenarios":"The step is configured to modify/replace field X, but the incoming row stream has no field named X and no rename field is specified.","commonSituations":"Upstream step renamed or removed the field, the transformation was reordered so the field isn't yet defined, or a typo in the field name in the step config.","solutions":["Add the missing field upstream (e.g. via a Select values / Get variables step) or fix the field name in the Script step config.","Specify the correct 'rename' field in the step settings if the field has a new name.","Use 'Show input fields' in Spoon to verify the actual incoming field names.","Reorder steps so the field exists before the Script step."],"exampleFix":"// before (step config)\nfieldName: \"amount_old\"\n// after\nfieldName: \"amount\"  // matches actual upstream field","handlingStrategy":"validation","validationCode":"// Pre-check in Spoon or via Kettle API before running the step\nRowMetaInterface input = ...;\nfor (String field : configuredFieldNames) {\n  if (input.indexOfValue(field) < 0) throw new IllegalStateException(\"Missing field: \" + field);\n}","typeGuard":null,"tryCatchPattern":"try { step.getFields(rowMeta, origin, info, target, meta, variables); } catch (KettleStepException e) {\n  // e.getMessage() names the missing field; repair upstream or config\n}","preventionTips":["Use Spoon's 'Show input fields' before configuring replace fields.","Keep field names synchronized when refactoring upstream steps.","Avoid renaming fields without updating dependent steps."],"tags":["kettle","field-resolution","step-config","row-metadata"],"backgroundTag":"record-not-found","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}