Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
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.
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;
}
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;
}
Is it possible to get the display value for specific attributes instead of this? I am using PersistableAdapter
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