Skip to main content
12-Amethyst
April 8, 2013
Solved

Windchill Customization(Giving constraint to an attribute)

  • April 8, 2013
  • 2 replies
  • 13223 views

Hi everybody !

I am very new to this forum & very beginner to windchill 10.1.

Is this possible to add constraint to an attribute through program.

(ex. SingleValuedConstraint, LegalValueList)

Best answer by KD_01

Using this code has one demerit

The OOTB processor can’t persist the value so you have to write a custom processor also.

2 replies

1-Visitor
April 8, 2013

For WC 9.1:

In my experience, manipulating the AttributeContainer of the IBAHolder and the related View objects is overly complex. That statement's probably debatable, but directly manipulating the Persistable constraints seems much easier.

Here's an example of creating a DiscreteSet constraint:

Object values[] = new Object[]{"Blue","Red","Green"};

DiscreteSet ds = new DiscreteSet(values);

WTTypeDefinition td = ....

AttributeDefinition ad = ....;

TypeSingleAttrConstraint constraint = new TypeSingleAttrConstraint();

constraint.setTypeDefinition(td);

constraint.setAttributeDefinition(AttributeDefinitionReference.newAttributeDefinitionReference((AbstractAttributeDefinition)ad));

constraint.setBindingRuleClassName(SingleAttributeConstraintBindingRule.class.getName());

constraint.setEnforcementRuleClassName(DiscreteSetConstraint.class.getName());

constraint.setEnforcementRuleData(ds);

constraint = save/insert(constraint);

You may want to clear/reset any applicable cache afterwards.

KD_0112-AmethystAuthor
12-Amethyst
April 9, 2013

Thanks Matthew.

I am in 10.1 and what I want to do is suppose there is one soft attribute of Document named "New". Now I need a dropdown box in the UI with some value like the attached picture and again that attribute will be a multi valued attribute.

So, how to do that?

I want to give the value programmatically cause those values will come from a txt file.Untitled.png

KD_0112-AmethystAuthor
12-Amethyst
November 6, 2013

Hi,

I assume that the IBA’s internal name is VendorName and it’s only in a specific subtype of WTDocument whose

internal name is com.ptc.Agenda.

For Create Mode :-

package ext.customization.processor;

import java.util.Arrays;

import java.util.Enumeration;

import java.util.HashSet;

import java.util.Iterator;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import wt.doc.WTDocument;

import wt.fc.ObjectReference;

import wt.fc.Persistable;

import wt.fc.PersistenceHelper;

import wt.folder.Folder;

import wt.util.WTException;

import com.ptc.core.components.beans.ObjectBean;

import com.ptc.core.components.forms.FormResult;

import com.ptc.core.lwc.server.LWCNormalizedObject;

import com.ptc.core.meta.common.TypeIdentifierHelper;

import com.ptc.core.meta.common.UpdateOperationIdentifier;

import com.ptc.netmarkets.util.beans.NmCommandBean;

import com.ptc.windchill.enterprise.doc.forms.CreateDocFormProcessor;

import com.ptc.windchill.wp.delivery.DeliveryRecord;

public class CustomDocProcessor extends CreateDocFormProcessor

{

@SuppressWarnings({ "rawtypes", "unchecked" })

@Override

public FormResult postProcess(NmCommandBean paramNmCommandBean,

List<ObjectBean> paramList) throws WTException

{

/* Taking the object of WTDocument which is created form the CreateDocFromProcessor*/

WTDocument localWTDocument = null;

for (Iterator localIterator = paramList.iterator(); localIterator.hasNext(); )

localWTDocument = (WTDocument)(((ObjectBean)localIterator.next()).getObject());

try{ /* Checking whether the WTDocument is of desired subtype */

if(( TypeIdentifierHelper.getType(localWTDocument).toString().equals("WCTYPE|wt.doc.WTDocument|

com.ptc.Agenda ")))//internal name of your subtype

{

HttpServletRequest req = paramNmCommandBean.getRequest();

Enumeration em = req.getParameterNames();

String temp = null;

while(em.hasMoreElements())

{

String name="VendorName";//internal name of your iba

String old = "old";

temp = em.nextElement().toString();

if(temp.contains(name) && !temp.endsWith(old))

break;

}

//Giving value to the soft attribute

LWCNormalizedObject obj = new LWCNormalizedObject(localWTDocument,null,null,new

UpdateOperationIdentifier());

//removing duplicate value

obj.load("VendorName");

obj.set("VendorName",(String[])new HashSet( Arrays.asList( req.getParameterValues(temp) )

).toArray( new String[]{} ));

/*persisting the value of IBA after removing duplicate value*/

obj.apply();

PersistenceHelper.manager.modify(localWTDocument);

}

}

catch(WTException e)

{

e.printStackTrace();

}

// TODO Auto-generated method stub

return super.postProcess(paramNmCommandBean, paramList);

}

}

17-Peridot
January 5, 2015

Hi, in 10.2 you have this OOTB, called "External Enumerated Value List". There you can pull the values from a text file or even from a DB like ERP.

wcbru_10_2_M020.png
Happy New Year!
Björn
1-Visitor
May 19, 2015

Hi Kaushik,

I have one doubt. I have one custom column. I want to publish the value of distribution target there. How can I get the value of Distribution target name or number in that column?

I mean, how can I fetch the data of Distribution target IBA there?

Thanks,

Sakil