{"record":{"id":"7244ad81c9fefbac","repo":"pentaho/pentaho-kettle","slug":"flattenermeta-exception-flattenfieldrequired","errorCode":"FlattenerMeta.Exception.FlattenFieldRequired","errorMessage":"FlattenerMeta.Exception.FlattenFieldRequired","messagePattern":"FlattenerMeta\\.Exception\\.FlattenFieldRequired","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/flattener/FlattenerMeta.java","lineNumber":123,"sourceCode":"    if ( fieldName != null && fieldName.length() > 0 ) {\n      int idx = row.indexOfValue( fieldName );\n      if ( idx < 0 ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"FlattenerMeta.Exception.UnableToLocateFieldInInputFields\", fieldName ) );\n      }\n\n      ValueMetaInterface v = row.getValueMeta( idx );\n      row.removeValueMeta( idx );\n\n      for ( int i = 0; i < targetField.length; i++ ) {\n        ValueMetaInterface value = v.clone();\n        value.setName( targetField[i] );\n        value.setOrigin( name );\n\n        row.addValueMeta( value );\n      }\n    } else {\n      throw new KettleStepException( BaseMessages.getString( PKG, \"FlattenerMeta.Exception.FlattenFieldRequired\" ) );\n    }\n  }\n\n  private void readData( Node stepnode ) throws KettleXMLException {\n    try {\n      fieldName = XMLHandler.getTagValue( stepnode, \"field_name\" );\n\n      Node fields = XMLHandler.getSubNode( stepnode, \"fields\" );\n      int nrfields = XMLHandler.countNodes( fields, \"field\" );\n\n      allocate( nrfields );\n\n      for ( int i = 0; i < nrfields; i++ ) {\n        Node fnode = XMLHandler.getSubNodeByNr( fields, \"field\", i );\n        targetField[i] = XMLHandler.getTagValue( fnode, \"name\" );\n      }\n    } catch ( Exception e ) {\n      throw new KettleXMLException( BaseMessages.getString(","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/flattener/FlattenerMeta.java#L105-L141","documentation":"FlattenerMeta.getFields throws KettleStepException with this localized message when no target fields are configured for the flattener (targetField is empty/null), so the step would produce no output columns. It is a configuration-completeness check.","triggerScenarios":"Executing a Flattener step where loadXML/readRep produced an empty targetField array — e.g., the step was never configured, or its <fields> list was lost.","commonSituations":"Step copied from a broken transformation; fields list cleared accidentally in the dialog; repository/XML load that silently dropped the target fields; building the transformation programmatically without setting target fields.","solutions":["Open the Flattener dialog and add at least one target field name","Verify the saved XML/repository entry contains the <fields><field><name> entries","When building metadata in code, call allocate(n) and populate targetField before execution","Re-save the transformation after configuring to persist the field list"],"exampleFix":"// before\nflattenerMeta.allocate( 0 ); // no targets -> FlattenFieldRequired\n// after\nflattenerMeta.allocate( 1 );\nflattenerMeta.setTargetField( new String[] { \"flattened_value\" } );","handlingStrategy":"validation","validationCode":"// before running: ensure at least one target field is configured\nString[] targets = flattenerMeta.getTargetField();\nif ( targets == null || targets.length == 0 ) {\n  throw new IllegalStateException( \"Flattener step has no target fields configured\" );\n}","typeGuard":null,"tryCatchPattern":"try {\n  trans.execute( null );\n} catch ( KettleStepException e ) {\n  if ( String.valueOf( e.getMessage() ).contains( \"FlattenFieldRequired\" ) ||\n       String.valueOf( e.getMessage() ).contains( \"flatten field\" ) ) {\n    // open the step dialog and add target fields\n  }\n}","preventionTips":["Configure target fields before saving/running","Check for empty <fields> blocks when copying steps","Populate metadata via allocate()+setTargetField in code","Re-save transformations after imports to persist field lists"],"tags":["pdi","kettle","config","flattener"],"backgroundTag":"missing-required-config-field","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"}