Hi,
I get a display name with following logic.
I hope this will be helpful to you.
PersistableAdapter persistableAdapter = new PersistableAdapter(object, null, locale, null);
persistableAdapter.load(ATTRIBUTE_INTERNAL_NAME);
Object attributeValue = persistableAdapter.get(ATTRIBUTE_INTERNAL_NAME);
AttributeTypeSummary attributeTypeSummary = persistableAdapter.getAttributeDescriptor(ATTRIBUTE_INTERNAL_NAME);
String displayName = getDisplayValue(attributeValue, attributeTypeSummary, locale);
private static String getDisplayValue(Object attributeValue, AttributeTypeSummary ats, Locale locale) {
String result;
DataSet ds = ats.getLegalValueSet();
if (attributeValue instanceof Timestamp) {
// Date
String dataFormat = ats.getDateDisplayFormat();
if (dataFormat == null || dataFormat.isEmpty()) {
dataFormat = DateFormatter.getDefaultDisplayFormat(false, locale);
}
result = getDisplayDateValue((Timestamp) attributeValue, dataFormat, locale);
} else if (attributeValue instanceof Number && !(attributeValue instanceof FloatingPointWithUnits)) {
// Number type
result = attributeValue.toString();
} else if (attributeValue instanceof String && ds != null && ds instanceof EnumeratedSet) {
// Enum
EnumerationEntryIdentifier eei = ((EnumeratedSet) ds).getElementByKey(attributeValue.toString());
LWCEnumerationEntryValuesFactory eevf = new LWCEnumerationEntryValuesFactory();
LocalizedValues localizedValues = eevf.get(eei, locale);
result = localizedValues == null ? attributeValue.toString() : localizedValues.getDisplay();
} else {
result = DataTypesUtility.toString(attributeValue, locale);
}
return result;
}