API to get display name for attributes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
API to get display name for attributes?
I am trying to retrieve display name for an attribute in WTPart or WTDocument. I can retrieve attribute values using the internal name of the attribute but would like to also get the display name using same process. Is there an API for this?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Is it possible to get the display value for specific attributes instead of this? I am using PersistableAdapter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Saw this post and thought, now there's a new request.
An easy way to do this that is completely independent of the attribute's datatype (String, Long, etc) is to use an sql query run from your Java class.
From Type and Attribute Manager we see Company Name.
If I pass my utility an attribute holder, such as a WTDocument, and the attribute's internal name the attribute's display name is returned. Seems to work.
BTW, You need to navigate six tables in total from WTDocument or WTPart (or whatever class) to finally get the display value.
David
