Skip to main content
6-Contributor
June 29, 2023
Solved

WTPartUsage link creation using API

  • June 29, 2023
  • 1 reply
  • 1828 views

How to create WtPartUsageLink in windchill 11. 1 through API. I am looking for one Sample.

 

Best answer by RandyJones

 

// work in process parent
// WorkInProgressHelper.service.checkout
WTPart parent;
WTPart component;

// create a Quantity
Quantity qty = new Quantity();
qty.setAmount(1);
qty.setUnit(QuantityUnit.EA);

// create the usagelink
WTPartUsageLink usageLink = WTPartUsageLink.newWTPartUsageLink(parent, component.getMaster());

// set the usagelink quantity
usageLink.setQuantity(qty);

// persist the usagelink
usageLink = (WTPartUsageLink) PersistenceHelper.manager.save(usageLink);

 

1 reply

20-Turquoise
June 29, 2023

 

// work in process parent
// WorkInProgressHelper.service.checkout
WTPart parent;
WTPart component;

// create a Quantity
Quantity qty = new Quantity();
qty.setAmount(1);
qty.setUnit(QuantityUnit.EA);

// create the usagelink
WTPartUsageLink usageLink = WTPartUsageLink.newWTPartUsageLink(parent, component.getMaster());

// set the usagelink quantity
usageLink.setQuantity(qty);

// persist the usagelink
usageLink = (WTPartUsageLink) PersistenceHelper.manager.save(usageLink);

 

14-Alexandrite
March 8, 2025

I'm having a problem with this. I am able to successfully add the child to the parent using this code, but later if I delete the parent and then try to checkout the child in the UI, it fails. I get a message saying the deleted parent is "deleted or inaccessible". The wtpartusagelink isn't cleaned up in the db when I delete the parent part. It still refers to the deleted part. Can you test this?

20-Turquoise
March 10, 2025

@dmcalister-2 wrote:

I'm having a problem with this. I am able to successfully add the child to the parent using this code, but later if I delete the parent and then try to checkout the child in the UI, it fails. I get a message saying the deleted parent is "deleted or inaccessible". The wtpartusagelink isn't cleaned up in the db when I delete the parent part. It still refers to the deleted part. Can you test this?


Works for me. You did not specify how you deleted the parent. I deleted the parent thru the UI.

Windchill 13.0.2.2