Skip to main content
1-Visitor
February 4, 2009
Question

Java Code to add Windchill IBA Values to WTPart Object

  • February 4, 2009
  • 5 replies
  • 14397 views
Hi, I have written java code using Windchill API to create WTPart. Object is getting created but added IBA values are NOT getting displayed on info page of the WTPart object in UI. IBA values are getting added to attribute container but not getting associted with created WTPart object. Can anyone help me out please? Thanks, Rekha Bhosale

5 replies

1-Visitor
February 5, 2009
http://www.datajett.com/windchill/wc_dev/ext_tools/src/ext/tools/UpdateIBAs.java
rbhosale1-VisitorAuthor
1-Visitor
February 6, 2009
Hi Sergey - Thanks for the link. I have got the solution. Now I am able to create WTPart Object along with IBA values set. Thanks, Rekha
1-Visitor
February 9, 2009
Hi Rekha, Is there a way to update the IBA values of an object with the use of code()APIs, without increasing its iteration? i.e without check out/check in operation.
1-Visitor
February 11, 2015

does anybody have idea how to modify iba value without iteration. with or without checkin check out

Thanks

1-Visitor
February 11, 2015

Hello Anurag,

As it has been said earlier, it is not advisable to update IBA without iterating the object.

But, having said that you can use below snippet to do so.

public static Persistable updateIBAValue(IBAHolder ibaHolder, String ibaName, Object ibaValue)
throws RemoteException, WTException, WTPropertyVetoException
{
logger.debug("...Inside updateIBAValue...");
ibaHolder = IBAValueHelper.service.refreshAttributeContainer(ibaHolder, null, null, null);
StandardIBADefinitionService defService = new StandardIBADefinitionService();
DefaultAttributeContainer attributeContainer = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();
AttributeDefDefaultView attributeDefinition = defService.getAttributeDefDefaultViewByPath(ibaName);

AbstractContextualValueDefaultView attrValue = null;
AbstractValueView abstractValueView[] = attributeContainer.getAttributeValues(attributeDefinition);
logger.debug("abstractValueView.length..."+abstractValueView.length);
if ((abstractValueView.length == 0))
{ // No existing value, needs to be created if approvedDate argument has a value

if (null != ibaValue)
{

if (attributeDefinition instanceof TimestampDefView && ibaValue instanceof Timestamp)
{
logger.debug("attributeDefinition is TimestampDefView...");
attrValue = new TimestampValueDefaultView((TimestampDefView) attributeDefinition,
(Timestamp) ibaValue);

}
else if (attributeDefinition instanceof StringDefView)
{
logger.debug("attributeDefinition is StringDefView...");
attrValue = new StringValueDefaultView((StringDefView) attributeDefinition, ibaValue.toString());

}
else if (attributeDefinition instanceof FloatDefView)
{
logger.debug("attributeDefinition is FloatDefView...");
if(ibaValue instanceof FloatingPoint){
logger.debug("ibaValue is FloatingPoint..."+ibaValue);
ibaValue = ((FloatingPoint)ibaValue).getValue();
logger.debug("ibaValue..."+ibaValue);
}

attrValue = new FloatValueDefaultView((FloatDefView) attributeDefinition, (Double) ibaValue, 5);

}

else if (attributeDefinition instanceof IntegerDefView)
{
logger.debug("attributeDefinition is IntegerDefView...");
attrValue = new IntegerValueDefaultView((IntegerDefView) attributeDefinition, (Long) ibaValue);

}
attributeContainer.addAttributeValue(attrValue);
}
else
{
System.out.println("ibaValue is null...");
return (Persistable)ibaHolder;
}
}
else
{ // Has existing value, needs to be updated/resetted
AbstractValueView avv = abstractValueView[0];
if (null == ibaValue)
{// Reset case

attributeContainer.deleteAttributeValue(avv);

}
else
{ // Update case

logger.debug("Update Case...");
if (avv instanceof TimestampValueDefaultView)
{
logger.debug("avv is TimestampValueDefaultView...");
((TimestampValueDefaultView) avv).setValue((Timestamp) ibaValue);

}
else if (avv instanceof StringValueDefaultView)
{
logger.debug("avv is StringValueDefaultView...");
((StringValueDefaultView) avv).setValue(ibaValue.toString());

}
else if (avv instanceof FloatValueDefaultView)
{
logger.debug("avv is FloatValueDefaultView...");
if(ibaValue instanceof FloatingPoint){
logger.debug("ibaValue is FloatingPoint for Update case..."+ibaValue);
ibaValue = ((FloatingPoint)ibaValue).getValue();
logger.debug("ibaValue..."+ibaValue);
}
((FloatValueDefaultView) avv).setValue((Double) ibaValue);

}
else if (avv instanceof IntegerValueDefaultView)
{
logger.debug("avv is IntegerValueDefaultView...");
((IntegerValueDefaultView) avv).setValue((Long) ibaValue);
}
attributeContainer.updateAttributeValue(avv);

}

}
ibaHolder.setAttributeContainer(attributeContainer);
StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
WTCollection byPassIterationModifierSet = new WTHashSet();
byPassIterationModifierSet.add(ibaHolder);
WorkInProgressServerHelper.putInTxMapForValidateModifiable(byPassIterationModifierSet);
Persistable persObject = PersistenceHelper.manager.save((Persistable) ibaHolder);
// PersistenceServerHelper.manager.insert((Persistable)ibaHolder);
return persObject;
}

Please let me know, if you need any further info.

1-Visitor
June 16, 2015

Hi.

I have IBAs with names that appear to be like  "com.mycompany.MyAttribute".

I tried the code example above and am getting a null from this line:

AttributeDefDevaultview attributeDefinition = defService.getAttributeDefDefaultCviewByPath(ibaName);

It also gives a null if I try just "MyAttribute".

Are these a different flavor of IBA that needs a different set of API to get to?

Thanks in advance,

Kelly

17-Peridot
June 17, 2015

I'm using the supported PersistableAdapter to update attribute information. You need to checkout the object before updating the object.

CREATE

PersistableAdapter obj = new PersistableAdapter("com.acme.AcmePart",null,null);

obj.load("name","number");

obj.set("name","my name");

obj.set("number","12345");

obj.persist();

10.1 Create with Folder information

LWCNormalizedObject obj = new LWCNormalizedObject("WCTYPE|wt.part.WTPart",null,null);

obj.load("name","containerReference","folder");

obj.set("name", "TestPart");

obj.set("containerReference", "OR:wt.pdmlink.PDMLinkProduct:1234"");

obj.set("folder", "/Default/Design/");

obj.persist();

10.2 Create with Folder information
PersistableAdapter obj = new PersistableAdapter("WCTYPE|wt.part.WTPart",null,null);

obj.load("name","containerReference","folder");
obj.set("name", "TestPart");
obj.set("containerReference", "OR:wt.pdmlink.PDMLinkProduct:1234"");
obj.set("folder.id", "/Default/Design/");
obj.persist();

Retrieve

PersistableAdapter obj = new PersistableAdapter(my_persistable,null,null,null);

obj.load("name","number","booleanValue");

Object nameValue = obj.get("name");

Object numberValue = obj.get("number");

Boolean booleanValue = (Boolean) obj.get("booleanValue");

Retrieve Multi Value Attribute

Object value = obj.get(attributeName);
if (value instanceof Object[]) {
Object values[] = (Object[]) value;

} else {
objValue = value;
}

UPDATE

PersistableAdapter obj = new PersistableAdapter(my_persistable,null,Locale.US,new UpdateOperationIdentifier());

obj.load("attributeA","attribtueB");

obj.set("attributeA",new Boolean(true));

obj.set("attribtueB","PURPLE");

obj.apply();

...

PersistenceHelper.manager.modify(my_persistable);

18-Opal
June 17, 2015

I don't know if people are aware of this, but there is a group dedicated to Windchill Customization, go check it out!  Windchill Customization

16-Pearl
December 17, 2024

Hi there,

 

I had a similar issue, where I tried to change an IBA - Value during a promotion request process.

Thanks to the discussion here, i was able to solve it.
I posted the whole procedure here:
https://community.ptc.com/t5/Windchill-Customization/Info-How-to-set-attribute-for-quot-released-by-quot-quot/m-p/988177