Skip to main content
12-Amethyst
September 19, 2023
Solved

How to get the constraints of a classification attribute

  • September 19, 2023
  • 1 reply
  • 1428 views

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

 

Best answer by Fadel

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

 

 

1 reply

Fadel
Fadel23-Emerald IAnswer
23-Emerald I
September 21, 2023

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

 

 

Buiꓘa
12-Amethyst
October 5, 2023

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