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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Update Primary Content of WTDocument from Primary Content of seperate WTDocument

BA_9563755
4-Participant

Update Primary Content of WTDocument from Primary Content of seperate WTDocument

Hello, 

Version: windchill pdmlink 12.0.2.7

 

I am trying to update the Primary Content of Doc2 with the Primary Content of Doc1 and am having trouble with the .updatePrimary method. Using the below code line 16 (.updatePrimary) keeps getting the error:

wt.util.WTException: java.lang.ClassCastException: class wt.content.ApplicationData cannot be cast to class wt.content.Aggregate (wt.content.ApplicationData and wt.content.Aggregate are in unnamed module of loader 'app')

 

Where would my mistake be? Thanks!

 

 

 

 

wt.doc.WTDocument Doc1 = (wt.doc.WTDocument) primaryBusinessObject;
Doc1 = (wt.doc.WTDocument) wt.vc.wip.WorkInProgressHelper.service.checkout(Doc1, wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder(), "").getWorkingCopy();
com.ptc.core.lwc.server.PersistableAdapter Doc1Pers = new com.ptc.core.lwc.server.PersistableAdapter(Doc1, null, java.util.Locale.US, new com.ptc.core.meta.common.UpdateOperationIdentifier());

// Gets the Primary from Doc2 and  Doc1
wt.content.ContentHolder Doc2ContentHolder = wt.content.ContentHelper.service.getContents((wt.content.ContentHolder) Doc2);
wt.content.ContentItem Doc2PrimaryContent = ((wt.content.FormatContentHolder) Doc2ContentHolder).getPrimary();

wt.content.ContentHolder Doc1ContentHolder = wt.content.ContentHelper.service.getContents((wt.content.ContentHolder) Doc1);
wt.content.ContentItem Doc1PrimaryContent = ((wt.content.FormatContentHolder) Doc1ContentHolder).getPrimary();

//Delete existing content from Doc 1
wt.content.ContentServerHelper.service.deleteContent((wt.content.ContentHolder)Doc1, Doc1PrimaryContent);

//Updates Doc1 with Doc2 content
wt.content.ContentServerHelper.service.updatePrimary((wt.content.FormatContentHolder) Doc1, (wt.content.ContentItem) Doc2PrimaryContent);

// Apply, Modify, and CheckIn the attributes to the New Doc object
Doc1 = (wt.doc.WTDocument) Doc1Pers.apply();
wt.fc.PersistenceHelper.manager.modify(Doc1);
wt.vc.wip.WorkInProgressHelper.service.checkin(Doc1, "Uploaded from Review");

 

 

 

 

 

 

1 REPLY 1
avillanueva
22-Sapphire II
(To:BA_9563755)

Is this workflow code? Perhaps try an alternate method at a lower level:

ApplicationData appDataNew = ApplicationData.newApplicationData(doc);
appDataNew.setFileName(fileName);
appDataNew.setRole(ContentRoleType.SECONDARY);
appDataNew = (ApplicationData)PersistenceHelper.manager.save(appDataNew);
InputStream is = ContentServerHelper.service.findContentStream(appData);
ContentServerHelper.service.updateContent(doc, appDataNew, is);

In your case you would setRole to PRIMARY.

Announcements

Top Tags