{"record":{"id":"a59b8921960d275d","repo":"pentaho/pentaho-kettle","slug":"unable-to-look-up-null-if-value-for-field","errorCode":null,"errorMessage":"Unable to look up Null if value for field ","messagePattern":"Unable to look up Null if value for field ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/datagrid/DataGridMeta.java","lineNumber":395,"sourceCode":"        }\n      } catch ( Exception e ) {\n        throw new KettleStepException( \"Unable to create value of type \" + fieldType[i], e );\n      }\n    }\n  }\n\n  public String getFieldNullIf( String fieldName ) throws KettleException {\n    int index;\n    boolean found = false;\n    String nullIfVal = null;\n    if ( null != fieldName ) {\n      for ( index = 0; index < this.getFieldName().length && !found; index++ ) {\n        found = fieldName.compareTo( this.getFieldName()[index] ) == 0;\n      }\n      if ( found ) {\n        nullIfVal = this.getFieldNullIf()[index - 1];\n      } else {\n        throw new KettleException( \"Unable to look up Null if value for field \" + fieldName );\n      }\n    }\n    return nullIfVal;\n  }\n\n  @Override\n  public String getXML() {\n    StringBuilder retval = new StringBuilder( 300 );\n\n    retval.append( \"    <fields>\" ).append( Const.CR );\n    for ( int i = 0; i < fieldName.length; i++ ) {\n      if ( fieldName[i] != null && fieldName[i].length() != 0 ) {\n        retval.append( \"      <field>\" ).append( Const.CR );\n        retval.append( SPACES_XML ).append( XMLHandler.addTagValue( \"name\", fieldName[i] ) );\n        retval.append( SPACES_XML ).append( XMLHandler.addTagValue( \"type\", fieldType[i] ) );\n        retval.append( SPACES_XML ).append( XMLHandler.addTagValue( \"format\", fieldFormat[i] ) );\n        retval.append( SPACES_XML ).append( XMLHandler.addTagValue( \"currency\", currency[i] ) );\n        retval.append( SPACES_XML ).append( XMLHandler.addTagValue( \"decimal\", decimal[i] ) );","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/datagrid/DataGridMeta.java#L377-L413","documentation":"getFieldNullIf resolves a field name to its 'null if' replacement string in the Data Grid. When the requested fieldName does not exist among the grid's field names, it throws this KettleException naming the field.","triggerScenarios":"Calling getFieldNullIf(fieldName) with a name that is not in this.getFieldName(); note the loop also scans off-by-one (index-1 after the found position), so callers passing a name that matches only partially or with different case also fail.","commonSituations":"Plugin/script code looking up a field that was renamed or deleted from the grid; case-sensitive name mismatch ('Qty' vs 'qty'); lookup before the step metadata finished loading.","solutions":["Verify the field name exists in the Data Grid (exact spelling and case) and correct the caller's argument.","Use getFieldNullIf(String) only after loading the step metadata (loadXML/readRep) so field arrays are populated.","Enumerate getFieldName() first and pick the exact entry instead of guessing the name.","If programmatic, match case-insensitively against the field list before calling."],"exampleFix":"// before\nString nv = meta.getFieldNullIf(\"qty\"); // not in grid\n// after\nif (Arrays.asList(meta.getFieldName()).contains(\"qty\")) {\n  String nv = meta.getFieldNullIf(\"qty\");\n}","handlingStrategy":"type-guard","validationCode":"boolean exists = Arrays.asList(meta.getFieldName()).contains(fieldName);\nif (!exists) throw new IllegalArgumentException(\"Field not in DataGrid: \" + fieldName);","typeGuard":"int fieldIndex(DataGridMeta m, String name){\n  String[] names = m.getFieldName();\n  for (int i=0;i<names.length;i++) if (names[i].equals(name)) return i;\n  return -1;\n}","tryCatchPattern":"try { String nv = meta.getFieldNullIf(fieldName); }\ncatch (KettleException e) {\n  logError(\"Field not found in DataGrid: \" + fieldName, e);\n  nv = null; // or fail fast depending on use\n}","preventionTips":["Look up fields with exact spelling/case as defined in the grid.","Call only after loadXML/readRep has populated the metadata.","Enumerate getFieldName() instead of guessing names.","Re-check lookups after any grid edit or rename."],"tags":["kettle","lookup-failure","field-not-found"],"backgroundTag":"record-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"}