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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

WF activity instructions that include attributes from Enum list not showing display name

Ben_A
10-Marble

WF activity instructions that include attributes from Enum list not showing display name

I trying to write some Workflow Activity instructions that include attributes (workflow variables) derived from enumerated lists chosen when creating the object. For example, we have a list of Technical Approves. Each approver has a unique internal name that is different from their display name.

 

The instructions need to say "talk with J. Baker about this" but they are coming out as "talk with TA_JBaker about this". The problem is even worse when the user's name has changed (i.e. through marriage their display name should now be J. Reynolds).

 

How can I tell the instructions to use the display name and not the internal name?

We are using Release 12.0.2.12 with PLMlink 12.0.2.7.

 

 

ACCEPTED SOLUTION

Accepted Solutions

@HelesicPetrand @BjoernRueegg Thank you both for your help on this. I got the following code working. It extracts the display name of a Global Enumerated Value.

 

 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("my_enum_attribute");
Object enumValue = obj.get("my_enum_attribute");

System.out.println("Attribute Value = internal name of Enumerated Value: " + (java.lang.String) obj.get("my_enum_attribute"));
//Returns TA_JBaker

com.ptc.core.meta.container.common.AttributeTypeSummary ats = obj.getAttributeDescriptor("my_enum_attribute");
com.ptc.core.meta.common.DataSet ds = ats.getLegalValueSet();
com.ptc.core.meta.common.EnumerationEntryIdentifier enumerationEntryIdentifier = ((com.ptc.core.meta.common.EnumeratedSet) ds).getElementByKey(enumValue.toString());
com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory lwcEnumerationEntryValuesFactory = new com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory();

//System.out.println(lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US));
//Returns: {IS_SELECTABLE=true, displayName=J. Reynolds, display=J. Reynolds, abbreviatedDisplay=J. Reynolds, selectable=true, fullDisplay=J. Reynolds, sort_order=0}

wt.meta.LocalizedValues localizedValues = lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US);
String enum_display_name = localizedValues.getDisplay();

System.out.println("Enumerated Value's Display Name: " + enum_display_name);
//Returns: J. Reynolds

 

 

View solution in original post

15 REPLIES 15
avillanueva
22-Sapphire II
(To:Ben_A)

You want to use user.getFullName() to see Display name.

But these are instructions written in the Activity tab of a task assignment node. Can I use code the activity tab? If so, that would be great. How though?

Right now I'm having to use: talk with {ta_name_wf} about this to show the value. Where ta_name_wf is the variable mapped to the attribute. 

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

You need to create new variable where you fill the display name by  code, and you use this attribute in the instructions.

PetrH 

Thanks for the help. I believe we're getting closer. I'm not actually after a user object class info. Just any value from an enumerated list.

 

This is my code so far. It returns the internal name of the enumeration, TA_JBaker but not the value which is "J. Reynolds"

 

com.ptc.core.lwc.server.PersistableAdapter obj1 = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj1.load("attrib_enum_username");
username_wf = obj1.getAsString("attrib_enum_username");
System.out.println(username_wf);

 

 

I can't find a method in PersistableAdapter to getDisplayName of the enumeration.

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

Because the method does not exists

CS133237-How to programmatically get the Display Name for Global Enumeration entries

HelesicPetr_0-1699254958161.png

You need to find unsupported method that exists in the system. 

 

PetrH

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

edit: oh this code does not work as I expected... sorry

 

Here is unsupported code to get value from IBA.

 

String iba_name = "ATRIBNAME";
String iba_value = "";

try {
	String name="";

	Object primaryBusinessObject = null;
	wt.iba.value.IBAHolder obj_iba_holder = (wt.iba.value.IBAHolder) primaryBusinessObject;
	wt.iba.value.IBAHolder iba_holder = wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer(obj_iba_holder, null, wt.util.WTContext.getContext().getLocale(), null);
	wt.iba.value.DefaultAttributeContainer default_attribute_container = (wt.iba.value.DefaultAttributeContainer) iba_holder.getAttributeContainer();

	for (wt.iba.value.litevalue.AbstractValueView abstract_value_view : default_attribute_container.getAttributeValues()) {
		name = abstract_value_view.getDefinition().getName();
		if (iba_name.equalsIgnoreCase(name)) {
			iba_value = wt.iba.value.IBAValueUtility.getLocalizedIBAValueDisplayString(abstract_value_view, Locale.getDefault());
			break;
		}
	}
} catch (RemoteException | WTException e) {
	e.printStackTrace();
}
System.out.println("display Value: " + iba_value);

 

PetrH

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

Why do you use PersistableAdapter method ?

Why do you not use the WTUser object?

 

example:

 

wt.org.WTUser wtUser = (wt.org.WTUser) wt.org.OrganizationServicesHelper.manager.getPrincipal("admin");
String userDisplayname = wtUser.getPrincipalDisplayIdentifier();

 

if you have correct user internal values you can search for the principal, and get the display name from the user.

PetrH 

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

Here I introduce a code to get enumeration display name. It is complicated but it works.


Input is internalValue of the parameter. 

 

iba_internalvalue = "internalValue";
QuerySpec qs = new QuerySpec();
int idxLWCLocalizablePropertyValue = qs.appendClassList(LWCLocalizablePropertyValue. class, false);
int idxLWCEnumerationEntry = qs.addClassList(LWCEnumerationEntry.class, false);
int idxLWCPropertyDefinition = qs.addClassList(LWCPropertyDefinition.class, false);
qs.appendSelect(new ClassAttribute(LWCLocalizablePropertyValue.class, "value"), new int[] { idxLWCLocalizablePropertyValue }, false);
qs.appendWhere(new SearchCondition(LWCEnumerationEntry.class , LWCEnumerationEntry.NAME , SearchCondition.EQUAL, iba_internalvalue), new int[] { idxLWCEnumerationEntry });
qs.appendAnd();
qs.appendWhere(new SearchCondition(LWCLocalizablePropertyValue.class ,"holderReference.key.id" ,LWCEnumerationEntry.class,"thePersistInfo.theObjectIdentifier.id"), new int[] {idxLWCLocalizablePropertyValue, idxLWCEnumerationEntry});
qs.appendAnd();
qs.appendWhere(new SearchCondition(LWCLocalizablePropertyValue.class ,"propertyReference.key.id" ,LWCPropertyDefinition.class,"thePersistInfo.theObjectIdentifier.id"), new int[] {idxLWCLocalizablePropertyValue,idxLWCPropertyDefinition});
qs.appendAnd();
qs.appendWhere(new SearchCondition(LWCPropertyDefinition.class , LWCPropertyDefinition.NAME , SearchCondition.EQUAL, "displayName"), new int[] { idxLWCPropertyDefinition });
QueryResult qr = PersistenceHelper.manager.find(qs);

while ( qr.hasMoreElements() ) {
	Object obj[] = (Object [])(qr.nextElement());
	System. out.println("Enumerations display name is: " +obj[0].toString());
}

 

Hope this can help you with enumeration iba values.

 

PS> it works if the internal name is used juts once in one enumeration list. If the internal name is used in two different lists then you need to search the correct one.

PetrH

Or something like this. The LocalizedValues variable has all information you need.

See also: CS204076 

 

  public static LocalizedValues getDisplayValueFromEnumerationAttribute(Persistable persistable,
                                                                        String attributeName,
                                                                        Locale locale)
      throws WTException {

    /* load object */
    PersistableAdapter obj = new PersistableAdapter(persistable,
                                                    null,
                                                    locale,
                                                    new DisplayOperationIdentifier());

    obj.load(attributeName);

    Object enumValue = obj.get(attributeName);
    AttributeTypeSummary ats = obj.getAttributeDescriptor(attributeName);
    DataSet ds = ats.getLegalValueSet();

    EnumerationEntryIdentifier enumerationEntryIdentifier = ((EnumeratedSet) ds).getElementByKey(
        enumValue.toString());
    LWCEnumerationEntryValuesFactory lwcEnumerationEntryValuesFactory = new LWCEnumerationEntryValuesFactory();
    return lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, locale);
  }

Bjoern 

Hi @BjoernRueegg,

 

This looks to be exactly what I'm after. So Simple. However, I'm not sure how to use it. When I try to insert this method (excuse me if method is the wrong term) into my Workflow expression bot I get an error on syntax check.

 

WfExpression_13305573.java:124: error: illegal start of expression
public static LocalizedValues getDisplayValueFromEnumerationAttribute(Persistable persistable, String attributeName, Locale locale)
^

 

How, or where, do I put this code so I can access it from a WF expression bot?

@Ben_A 

Sorry for the late answer. To put the code into a workflow expression you need to specify all the different java package names, since there is no import function in any expression.

You could compile the code in an external class and call it from the expression. But all of that needs some customizing knowledge.

@BjoernRueegg , @Ben_A 

all classes have to be fully defined. 

in your case you need to define all used classes

wt.meta.LocalizedValues
wt.fc.Persistable
java.util.Locale
com.ptc.core.lwc.server.PersistableAdapter
com.ptc.core.meta.container.common.AttributeTypeSummary
com.ptc.core.meta.common.DataSet
com.ptc.core.meta.common.EnumerationEntryIdentifier
com.ptc.core.meta.common.EnumeratedSet
com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory

PetrH

Ok. Adding the full class makes sense, so I updated my code as shown:

Everything up to the final line passes the syntax check.

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("my_attribute");

Object enumValue = obj.get("my_attribute");

com.ptc.core.meta.container.common.AttributeTypeSummary ats = obj.getAttributeDescriptor("my_attribute");
com.ptc.core.meta.common.DataSet ds = ats.getLegalValueSet();

com.ptc.core.meta.common.EnumerationEntryIdentifier enumerationEntryIdentifier = ((com.ptc.core.meta.common.EnumeratedSet) ds).getElementByKey(enumValue.toString());

com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory lwcEnumerationEntryValuesFactory = new com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory();

String Output = lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US);

But I get this error at the final line:

Checking Syntax...
WfExpression_13305573.java:54: error: incompatible types: LocalizedValues cannot be converted to String
String Output = lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US);

 

What exactly is the output from lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US); and how can I convert it into a string? I can't seam to find it mentioned anywhere in the JavaDoc.

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

String Output = lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US);

You can not use the String as a output because the .get function returns  LocalizedValues

You need to get a string from the LocalizedValues object.

 

PetrH

@HelesicPetrand @BjoernRueegg Thank you both for your help on this. I got the following code working. It extracts the display name of a Global Enumerated Value.

 

 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("my_enum_attribute");
Object enumValue = obj.get("my_enum_attribute");

System.out.println("Attribute Value = internal name of Enumerated Value: " + (java.lang.String) obj.get("my_enum_attribute"));
//Returns TA_JBaker

com.ptc.core.meta.container.common.AttributeTypeSummary ats = obj.getAttributeDescriptor("my_enum_attribute");
com.ptc.core.meta.common.DataSet ds = ats.getLegalValueSet();
com.ptc.core.meta.common.EnumerationEntryIdentifier enumerationEntryIdentifier = ((com.ptc.core.meta.common.EnumeratedSet) ds).getElementByKey(enumValue.toString());
com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory lwcEnumerationEntryValuesFactory = new com.ptc.core.lwc.server.LWCEnumerationEntryValuesFactory();

//System.out.println(lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US));
//Returns: {IS_SELECTABLE=true, displayName=J. Reynolds, display=J. Reynolds, abbreviatedDisplay=J. Reynolds, selectable=true, fullDisplay=J. Reynolds, sort_order=0}

wt.meta.LocalizedValues localizedValues = lwcEnumerationEntryValuesFactory.get(enumerationEntryIdentifier, java.util.Locale.US);
String enum_display_name = localizedValues.getDisplay();

System.out.println("Enumerated Value's Display Name: " + enum_display_name);
//Returns: J. Reynolds

 

 

Announcements


Top Tags