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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to update IBA String values on a Part without iterating?

NT_10748259
10-Marble

How to update IBA String values on a Part without iterating?

As per the title, how do you update string iba values without iterating. 

I know this is possible but cant seem to find the code to do so at the moment. 

ACCEPTED SOLUTION

Accepted Solutions

Hi @NT_10748259 

Check this thread Java Code to add Windchill IBA Values to WTPart Object

There is a code for the update 

 

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

PetrH

 

View solution in original post

2 REPLIES 2

Hi @NT_10748259 

Check this thread Java Code to add Windchill IBA Values to WTPart Object

There is a code for the update 

 

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

PetrH

 

Mat
15-Moonstone
15-Moonstone
(To:NT_10748259)

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

 

Announcements

Top Tags