cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Translate the entire conversation x

WTPartUsage link creation using API

KU_10670946
6-Contributor

WTPartUsage link creation using API

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

 

ACCEPTED SOLUTION

Accepted Solutions

 

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

 

View solution in original post

5 REPLIES 5

 

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

 

dmcalister-2
14-Alexandrite
(To:RandyJones)

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?


@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

dmcalister-2
14-Alexandrite
(To:RandyJones)

Deleted through the ui. It could be something else I'm doing in the code. Do you check the parent or child out/in? I'm not checking out the parent, but I do have to checkout the child to do some other things. 

 

Windchill 12.1.2.9

Hi @KU_10670946 

If the usage is not deleted, by system, you have to care about it.

That's all.

So if you delete the parent by code, you have to delete the all usage links

PetrH

Announcements
Top Tags