cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

API to get display name for attributes?

WM_9965332
11-Garnet

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?

1 ACCEPTED SOLUTION

Accepted Solutions
shin1h
13-Aquamarine
(To:WM_9965332)

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

 

 

 

 

View solution in original post

3 REPLIES 3
shin1h
13-Aquamarine
(To:WM_9965332)

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

 

 

 

 

WM_9965332_0-1656012572168.png

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.

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

 

Top Tags