Skip to main content
13-Aquamarine
May 17, 2022
Solved

API to get display name for attributes?

  • May 17, 2022
  • 2 replies
  • 6408 views

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?

Best answer by shin1h

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;
}

 

 

 

 

2 replies

shin1h13-AquamarineAnswer
13-Aquamarine
May 18, 2022

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;
}

 

 

 

 

13-Aquamarine
June 23, 2022

WM_9965332_0-1656012572168.png

Is it possible to get the display value for specific attributes instead of this? I am using PersistableAdapter

18-Opal
May 19, 2022

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.

d_graham_1-1652977361132.png

 

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.

d_graham_0-1652977141842.png

 

David