Skip to main content
Sep 19, 2023 11:12 AM UTC
Solved

How to get the constraints of a classification attribute

Hello,

 

I would like to retrieve the constraints of a classification attribute (Valid Range, Legal Value List, String Values, etc).

I tried it like mentioned in https://www.ptc.com/en/support/article/CS240966

 

PersistableAdapter persistableAdapter = new PersistableAdapter(manuPart, null, SessionHelper.manager.getLocale(),new DisplayOperationIdentifier());
AttributeTypeSummary attrDesc = persistableAdapter.getAttributeDescriptor(internalAttrName);

attrDesc.getLegalValueSet();
attrDesc.getConstraints();

 

getLegalValueSet() always returns null, even though all attributes I tried have at least 1 constraint.

getConstraints() is deprecated and also returns null.

 

I tried so many different approaches, nothing worked. I found another post from last year, where the same problem was described.

 

Is there another way to query attribute constraints, is there some kind of service for that?

 

Thanks and best regards

 

FadelAnswer
3-Newcomer
Sep 21, 2023 10:23 AM UTC

Hi , would you try below approach

 

 

TypeDefinitionReadView clfNodeView = TypeDefinitionServiceHelper.service.getTypeDefView(AttributeTemplateFlavor.LWCSTRUCT,
 "com.ptc.csm.default_clf_namespace", "<Classification Node Internal Name>");
 AttributeDefinitionReadView adrv = clfNodeView.getAttributeByName("<Classification Attribute Internal Name> ");
 Collection<ConstraintDefinitionReadView> constraints = adrv.getAllConstraints();
 System.out.println("constraints======>"+constraints);

 

 

2 replies

FadelAnswer
3-Newcomer
Sep 21, 2023 10:23 AM UTC

Hi , would you try below approach

 

 

TypeDefinitionReadView clfNodeView = TypeDefinitionServiceHelper.service.getTypeDefView(AttributeTemplateFlavor.LWCSTRUCT,
 "com.ptc.csm.default_clf_namespace", "<Classification Node Internal Name>");
 AttributeDefinitionReadView adrv = clfNodeView.getAttributeByName("<Classification Attribute Internal Name> ");
 Collection<ConstraintDefinitionReadView> constraints = adrv.getAllConstraints();
 System.out.println("constraints======>"+constraints);

 

 

Oct 5, 2023 11:21 AM UTC

Hi @fade, thanks a lot, this did the trick, it finally works.