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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

How can I print the enumeration display value depending on the attribute in the e-mail notification?

MI_10060660
10-Marble

How can I print the enumeration display value depending on the attribute in the e-mail notification?

Attribute Internal Name Name: ProjeAdi
Enumaration Internal Name: ProjeAdi

Enumaration Value:
Internal Name: AProject, Display Name: A Projesi
Internal Name: BProject, Display Name: B Projesi

 

 

wt.change2.VersionableChangeItem chg = (wt.change2.VersionableChangeItem)primaryBusinessObject;
com.ptc.core.lwc.server.PersistableAdapter obj = new
com.ptc.core.lwc.server.PersistableAdapter(chg,null,java.util.Locale.US,new com.ptc.core.meta.common.DisplayOperationIdentifier());

obj.load("number","name","theCategory","ProjeAdi");

IRNoVar = (String) obj.get ("number");
System.out.println("IRNoVar = "+IRNoVar);

IRAdiVar = (String) obj.get ("name");
System.out.println("IRAdiVar = "+IRAdiVar);

IRKategoriVar = (String) obj.get ("theCategory");
System.out.println("IRKategoriVar = "+IRKategoriVar);

IRProjeAdiVar = (String) obj.get ("ProjeAdi");
System.out.println("IRProjeAdiVar = "+IRProjeAdiVar);

 


In notification mail IRProjeAdiVar display name is Project Name

This code was written in windchill workflow expression robot.

The output value here is;

Project Name: AProject

But what we want here is,

Project Name : A Projesi.

How should I edit this code to get the output I want?

 

ACCEPTED SOLUTION

Accepted Solutions

Hi @MI_10060660 

You should have known how to do so.  You need to declare full class definition and also you can not write own method in the expresion.

String ATTRIBUTE_INTERNAL_NAME = "MYATTRIBUTE";
wt.change2.VersionableChangeItem object = (wt.change2.VersionableChangeItem)primaryBusinessObject;
java.util.Locale locale = java.util.Locale.US;
com.ptc.core.lwc.server.PersistableAdapter persistableAdapter = new com.ptc.core.lwc.server.PersistableAdapter(object, null,locale , null);
persistableAdapter.load(ATTRIBUTE_INTERNAL_NAME);
java.lang.Object attributeValue = persistableAdapter.get(ATTRIBUTE_INTERNAL_NAME);
com.ptc.core.meta.container.common.AttributeTypeSummary attributeTypeSummary = persistableAdapter.getAttributeDescriptor(ATTRIBUTE_INTERNAL_NAME);
com.ptc.core.meta.common.DataSet ds = attributeTypeSummary.getLegalValueSet();
// Enum
com.ptc.core.meta.common.EnumerationEntryIdentifier eei = ((com.ptc.core.meta.common.EnumeratedSet) ds).getElementByKey(attributeValue.toString());
com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory eevf = new com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory();
wt.meta.LocalizedValues localizedValues = eevf.get(eei, locale);

String displayName = localizedValues == null ? attributeValue.toString() : localizedValues.getDisplay();

Do not forget to look in a background log file if something goes wrong - there is not a type check so there can be some Can not cast error. 

PetrH

View solution in original post

10 REPLIES 10
Fadel
22-Sapphire II
(To:MI_10060660)

Try the same with legal value constraint

Fadel_0-1708427974753.png

 

Fede

Unfortunately, I cannot do this. There is a cascading attributes with enumeration.

Hi @MI_10060660 

Try this code

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

PetrH

I tried this code but I couldn't run it and therefore I didn't get any results.

Hi @MI_10060660 

The code can not be used directly in workflow

You need to create own class to use this code and call it from the workflow

or rewrite the code with all unnecessary definition and then you can use it in the workflow 

PetrH

I tried but there was no solution.

Hi @MI_10060660 

What do you mean no solution? The code works and give you an enumeration display name.

EnumerationEntryIdentifier eei = ((EnumeratedSet) ds).getElementByKey(attributeValue.toString());
		LWCEnumerationEntryValuesFactory eevf = new LWCEnumerationEntryValuesFactory();
		LocalizedValues localizedValues = eevf.get(eei, locale);
		result = localizedValues == null ? attributeValue.toString() : localizedValues.getDisplay();

PetrH

Could you give me an example code in workflow?

Hi @MI_10060660 

You should have known how to do so.  You need to declare full class definition and also you can not write own method in the expresion.

String ATTRIBUTE_INTERNAL_NAME = "MYATTRIBUTE";
wt.change2.VersionableChangeItem object = (wt.change2.VersionableChangeItem)primaryBusinessObject;
java.util.Locale locale = java.util.Locale.US;
com.ptc.core.lwc.server.PersistableAdapter persistableAdapter = new com.ptc.core.lwc.server.PersistableAdapter(object, null,locale , null);
persistableAdapter.load(ATTRIBUTE_INTERNAL_NAME);
java.lang.Object attributeValue = persistableAdapter.get(ATTRIBUTE_INTERNAL_NAME);
com.ptc.core.meta.container.common.AttributeTypeSummary attributeTypeSummary = persistableAdapter.getAttributeDescriptor(ATTRIBUTE_INTERNAL_NAME);
com.ptc.core.meta.common.DataSet ds = attributeTypeSummary.getLegalValueSet();
// Enum
com.ptc.core.meta.common.EnumerationEntryIdentifier eei = ((com.ptc.core.meta.common.EnumeratedSet) ds).getElementByKey(attributeValue.toString());
com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory eevf = new com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory();
wt.meta.LocalizedValues localizedValues = eevf.get(eei, locale);

String displayName = localizedValues == null ? attributeValue.toString() : localizedValues.getDisplay();

Do not forget to look in a background log file if something goes wrong - there is not a type check so there can be some Can not cast error. 

PetrH

I still haven't gotten a complete solution to my problem.

Announcements

Top Tags