{"record":{"id":"070357c8b596c747","repo":"pentaho/pentaho-kettle","slug":"switchcase-exception-unabletofindfieldname","errorCode":null,"errorMessage":"SwitchCase.Exception.UnableToFindFieldName","messagePattern":"SwitchCase\\.Exception\\.UnableToFindFieldName","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/switchcase/SwitchCase.java","lineNumber":154,"sourceCode":"   * <li>will copy input row meta info, fields info, etc. step related info\n   * <li>will get step IO meta info and discover target streams for target output steps\n   * <li>for every target output find output rowset and expected value.\n   * <li>for every discovered output rowset put it as a key-value: 'expected value'-'output rowSet'. If expected value\n   * is null - put output rowset to special 'null set' (avoid usage of null as a map keys)\n   * <li>Discover default row set. We expect only one default rowset, even if technically can have many. *\n   * </ol>\n   *\n   * @throws KettleException\n   *           if something goes wrong during step preparation.\n   */\n  void createOutputValueMapping() throws KettleException {\n    data.outputRowMeta = getInputRowMeta().clone();\n    meta.getFields( getTransMeta().getBowl(), data.outputRowMeta, getStepname(), null, null, this, repository,\n      metaStore );\n\n    data.fieldIndex = getInputRowMeta().indexOfValue( meta.getFieldname() );\n    if ( data.fieldIndex < 0 ) {\n      throw new KettleException( BaseMessages.getString( PKG, \"SwitchCase.Exception.UnableToFindFieldName\", meta\n        .getFieldname() ) );\n    }\n\n    data.inputValueMeta = getInputRowMeta().getValueMeta( data.fieldIndex );\n\n    try {\n      StepIOMetaInterface ioMeta = meta.getStepIOMeta();\n\n      // There is one or many case target for each target stream.\n      // The ioMeta object has one more target stream for the default target though.\n      //\n      List<StreamInterface> targetStreams = ioMeta.getTargetStreams();\n      for ( int i = 0; i < targetStreams.size(); i++ ) {\n        SwitchCaseTarget target = (SwitchCaseTarget) targetStreams.get( i ).getSubject();\n        if ( target == null ) {\n          break; // Skip over default option\n        }\n        if ( target.caseTargetStep == null ) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/switchcase/SwitchCase.java#L136-L172","documentation":"KettleException thrown by SwitchCase.createOutputValueMapping when the field name configured in the Switch/Case step metadata cannot be found in the incoming row's row meta (indexOfValue returns -1). This happens once per step initialization inside processRow before any case-value mapping is built. The error message includes the missing field name from meta.getFieldname().","triggerScenarios":"Running a transformation where the Switch/Case step's 'field name to switch' does not exist in the input stream: the upstream step was renamed/deleted, the field is produced by a later step, or the field name is misspelled or has different casing/whitespace.","commonSituations":"Renaming a field in an upstream step (e.g., Select Values or Calculator) without updating Switch/Case; changing a source table column name; moving Switch/Case before the step that creates the field; case-sensitivity mismatches after editing metadata in XML.","solutions":["Open the Switch/Case step and set 'Field name to switch' to a field that actually exists in the input stream (check upstream preview output).","Fix upstream steps so the switch field is produced before this step, or move the Switch/Case step later in the hop chain.","Correct spelling/case/whitespace of the field name to exactly match the stream field.","Re-edit the transformation after any upstream field rename to refresh the step metadata."],"exampleFix":"// before: field renamed upstream but not here\nSwitchCaseMeta meta = ...; meta.setFieldname(\"cust_id\");\n// after: match the actual upstream field\nmeta.setFieldname(\"customer_id\");","handlingStrategy":"validation","validationCode":"// validate the switch field exists in the incoming stream\nString field = meta.getFieldname();\nif ( field == null || inputRowMeta.indexOfValue( field ) < 0 ) {\n  throw new KettleException( \"Switch field not in stream: \" + field );\n}","typeGuard":null,"tryCatchPattern":"try { runTransformation(); } catch ( KettleException e ) { if ( e.getMessage().contains( \"UnableToFindFieldName\" ) || e.getMessage().contains( field ) ) { log.error( \"Fix the switch field: \" + field ); } throw e; }","preventionTips":["Preview upstream output and confirm field names before configuring Switch/Case.","Update Switch/Case metadata whenever upstream fields are renamed.","Watch for case/whitespace differences in field names.","Use Get Fields in the dialog instead of typing names manually."],"tags":["kettle","switch-case","field-not-found","transform"],"backgroundTag":"entity-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"}