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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

How to get the constraints of a classification attribute

TG_10272716
12-Amethyst

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

 

ACCEPTED SOLUTION

Accepted Solutions
Fadel
22-Sapphire I
(To:TG_10272716)

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

 

 

Fede

View solution in original post

2 REPLIES 2
Fadel
22-Sapphire I
(To:TG_10272716)

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

 

 

Fede
TG_10272716
12-Amethyst
(To:Fadel)

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

Announcements

Top Tags