{"record":{"id":"1955b3f01cb0bcd8","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmetamod-exception-fieldtoreplacenotfound-1955b3","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/ScriptValuesMod.java","lineNumber":157,"sourceCode":"      // What is the output row looking like?\n      //\n      data.outputRowMeta = getInputRowMeta().clone();\n      meta.getFields( getTransMeta().getBowl(), data.outputRowMeta, getStepname(), null, null, this, repository,\n        metaStore );\n\n      // Determine the indexes of the fields used!\n      //\n      determineUsedFields( rowMeta );\n\n      // Get the indexes of the replaced fields...\n      //\n      data.replaceIndex = new int[ meta.getFieldname().length ];\n      for ( int i = 0; i < meta.getFieldname().length; i++ ) {\n        if ( meta.getReplace()[ i ] ) {\n          data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getFieldname()[ i ] );\n          if ( data.replaceIndex[ i ] < 0 ) {\n            if ( Utils.isEmpty( meta.getFieldname()[ i ] ) ) {\n              throw new KettleStepException( BaseMessages.getString(\n                PKG, \"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound\", meta.getFieldname()[ i ] ) );\n            }\n            data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getRename()[ i ] );\n            if ( data.replaceIndex[ i ] < 0 ) {\n              throw new KettleStepException( BaseMessages.getString(\n                PKG, \"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound\", meta.getRename()[ i ] ) );\n            }\n          }\n        } else {\n          data.replaceIndex[ i ] = -1;\n        }\n      }\n\n      // set the optimization level\n      data.cx = ContextFactory.getGlobal().enterContext();\n\n      try {\n        String optimizationLevelAsString = environmentSubstitute( meta.getOptimizationLevel() );","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L139-L175","documentation":"The ScriptValuesMod step is configured with replace=true for a field, but the field to replace could not be found in the incoming row's row metadata (rowMeta.indexOfValue returned < 0), neither by the original field name nor (after falling back) by the rename. Kettle throws this KettleStepException during addValues, aborting the step before any rows are processed.","triggerScenarios":"processRow -> addValues with meta.getReplace()[i]==true while meta.getFieldname()[i] is not in the incoming row layout; the fallback lookup of meta.getRename()[i] in the row layout also fails; note the empty-fieldname branch throws this same message even when the name is empty.","commonSituations":"An upstream step was renamed or removed so the field no longer exists in the stream; field renamed case-sensitively (e.g. 'Name' vs 'name'); transformation edited to rename the output field but 'replace' still points at the old name; the step's 'replace' checkbox left on after changing the field mapping.","solutions":["Open the ScriptValuesMod step and untick 'replace' or set the field name to one that exists in the input stream","Check which field name the exception names (fieldname or rename) and align it with the upstream row layout (use 'Show input fields')","Insert a 'Select values' / 'Field exists' step or fix the upstream step so the field is always present before this step","Verify case-sensitive spelling of the field name — Kettle field lookups are case-sensitive","Re-save the transformation after step renames so metadata references stay in sync"],"exampleFix":"// before: replace=true on missing field\nfieldname=\"old_total\", rename=\"\", replace=true  // row has 'total'\n// after: point replace at the actual field\nfieldname=\"total\", rename=\"\", replace=true","handlingStrategy":"validation","validationCode":"// validate the step config against the input row layout before running\nRowMetaInterface input = transMeta.getPrevStepFields(stepName);\nString[] names = meta.getFieldname();\nString[] renames = meta.getRename();\nboolean[] replace = meta.getReplace();\nfor (int i = 0; i < names.length; i++) {\n  if (replace[i] && input.indexOfValue(names[i]) < 0\n      && input.indexOfValue(renames[i]) < 0)\n    throw new KettleException(\"Replace target not in stream: \" + names[i]);\n}","typeGuard":null,"tryCatchPattern":"try {\n  trans.execute(null);\n} catch (KettleException e) {\n  if (BaseMessages.getString(PKG, \"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound\")\n      .matches(Pattern.quote(e.getMessage()).replaceAll(\"\\\\{.*\\\\}\", \".*\"))) {\n    logError(\"Fix the ScriptValuesMod replace field config: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["After renaming any upstream field, re-open downstream script steps and re-map replace targets","Remember field lookups are case-sensitive; keep naming conventions consistent","Use Spoon's 'Show input fields' on the step hop to confirm the replace field exists","Clear the 'replace' checkbox for fields that are new outputs, not replacements","Add a unit smoke test that loads the transformation and checks getPrevStepFields against step metadata"],"tags":["kettle","step-execution","field-lookup","runtime","metadata"],"backgroundTag":"resource-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"}