{"record":{"id":"a1f9730df8270737","repo":"pentaho/pentaho-kettle","slug":"unknown-field-specified-to-replace-with-a-formula-result-fn","errorCode":null,"errorMessage":"Unknown field specified to replace with a formula result: [+fn.getReplaceField()+]","messagePattern":"Unknown field specified to replace with a formula result: \\[\\+fn\\.getReplaceField\\(\\)\\+\\]","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/FormulaMeta.java","lineNumber":166,"sourceCode":"      if ( Utils.isEmpty( fn.getReplaceField() ) ) {\n        // Not replacing a field.\n        if ( !Utils.isEmpty( fn.getFieldName() ) ) {\n          // It's a new field!\n\n          try {\n            ValueMetaInterface v = ValueMetaFactory.createValueMeta( fn.getFieldName(), fn.getValueType() );\n            v.setLength( fn.getValueLength(), fn.getValuePrecision() );\n            v.setOrigin( name );\n            row.addValueMeta( v );\n          } catch ( Exception e ) {\n            throw new KettleStepException( e );\n          }\n        }\n      } else {\n        // Replacing a field\n        int index = row.indexOfValue( fn.getReplaceField() );\n        if ( index < 0 ) {\n          throw new KettleStepException( \"Unknown field specified to replace with a formula result: [\"\n            + fn.getReplaceField() + \"]\" );\n        }\n        // Change the data type etc.\n        //\n        ValueMetaInterface v = row.getValueMeta( index ).clone();\n        v.setLength( fn.getValueLength(), fn.getValuePrecision() );\n        v.setOrigin( name );\n        row.setValueMeta( index, v ); // replace it\n      }\n    }\n  }\n\n  /**\n   * Checks the settings of this step and puts the findings in a remarks List.\n   *\n   * @param remarks\n   *          The list to put the remarks in @see org.pentaho.di.core.CheckResult\n   * @param stepMeta","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/FormulaMeta.java#L148-L184","documentation":"KettleStepException thrown in FormulaMeta.getFields() during metadata resolution when a formula is configured to replace a field that does not exist in the incoming row layout. Unlike error 1461 (runtime row processing), this fires earlier while computing output fields from the input row meta.","triggerScenarios":"FormulaMetaFunction.replaceField is set but row.indexOfValue(replaceField) returns -1 when resolving fields against the input row meta — misspelled field, hop changed, or upstream field removed.","commonSituations":"Deleting a calculator field upstream and forgetting to update the Formula replace reference; plugging the Formula step onto a different stream; case-sensitivity mismatch in field names.","solutions":["Fix the 'Replace value' field name in the Formula dialog to match an existing input field.","Re-select the field via the dialog's field picker after changing upstream steps.","Use the transformation validator to catch dangling field references before execution.","If the field may be absent, add a Select Values step to define a default field first."],"exampleFix":"// before\nfn.setReplaceField(\"total_amt\");\n// after\nfn.setReplaceField(\"total_amount\"); // actual upstream field name","handlingStrategy":"validation","validationCode":"// design-time check mirroring getFields()\nfor (FormulaMetaFunction fn : meta.getFormula()) {\n  if (!Utils.isEmpty(fn.getReplaceField()) && rowMeta.indexOfValue(fn.getReplaceField()) < 0)\n    remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, \"Missing replace field: \" + fn.getReplaceField(), stepMeta));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the field picker for Replace value selections","Re-check formula steps after removing/reordering upstream steps","Run transformation validation before production runs"],"tags":["formula","field-lookup","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"}