diff --git a/org.adempiere.base/src/org/compiere/util/Env.java b/org.adempiere.base/src/org/compiere/util/Env.java index 0ef171534c..cc0bf8fed2 100644 --- a/org.adempiere.base/src/org/compiere/util/Env.java +++ b/org.adempiere.base/src/org/compiere/util/Env.java @@ -1674,14 +1674,25 @@ public final class Env else tableName = foreignTable; MTable table = MTable.get(ctx, tableName); - if (table != null && (tableName.equalsIgnoreCase(foreignTable) || tableName.equalsIgnoreCase(po.get_TableName()))) { + String keyCol = tableName + "_ID"; + boolean isSubTypeTable = false; + if (! Util.isEmpty(foreignTable) && ! tableName.equalsIgnoreCase(foreignTable)) { + // verify if is a subtype table + if ( table.getKeyColumns() != null + && table.getKeyColumns().length == 1 + && table.getKeyColumns()[0].equals(foreignTable + "_ID")) { + isSubTypeTable = true; + keyCol = foreignTable + "_ID"; + } + } + if (table != null && (isSubTypeTable || tableName.equalsIgnoreCase(foreignTable) || tableName.equalsIgnoreCase(po.get_TableName()))) { String columnName = tblIndex > 0 ? format.substring(tblIndex + 1) : format; MColumn column = table.getColumn(columnName); if (column != null) { if (column.isSecure()) { outStr.append("********"); } else { - String value = DB.getSQLValueString(trxName,"SELECT " + columnName + " FROM " + tableName + " WHERE " + tableName + "_ID = ?", (Integer)v); + String value = DB.getSQLValueString(trxName,"SELECT " + columnName + " FROM " + tableName + " WHERE " + keyCol + "=?", (Integer)v); if (value != null) outStr.append(value); }