{"record":{"id":"f483044721b493c4","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmetamod-exception-fieldtoreplacenotfound","errorCode":"ScriptValuesMetaMod.Exception.FieldToReplaceNotFound","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/script/Script.java","lineNumber":149,"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      data.cx = ScriptMeta.createNewScriptEngine( getStepname() );\n      data.scope = data.cx.getBindings( ScriptContext.ENGINE_SCOPE );\n\n      bFirstRun = true;\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java#L131-L167","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (metadata): replace=true, fieldname=\"\"\n// after (metadata): either fieldname=\"myField\" with replace=true,\n// or replace=false for a newly created output field","handlingStrategy":"validation","validationCode":"// before running, for each script field row:\nfor (int i = 0; i < meta.getFieldname().length; i++) {\n  if (meta.getReplace()[i] && Utils.isEmpty(meta.getFieldname()[i])) {\n    throw new IllegalStateException(\"Replace checked but Fieldname empty at row \" + i);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  step.processRow();\n} catch (KettleStepException e) {\n  if (e.getMessage().contains(\"FieldToReplaceNotFound\")) {\n    logError(\"Fix the script step fields grid: \" + e.getMessage());\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["kettle","javascript","field-lookup","configuration"],"backgroundTag":"missing-required-argument","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"}