Skip to main content
1-Visitor
October 18, 2012
Question

Rename WTDocument Primary Content File

  • October 18, 2012
  • 1 reply
  • 1073 views

Is it feasible to reanme a WTDocument primary content file?


I have tried the following via the Windchill API, however, the file name does not change.


ContentHolder contentHolder = ContentHelper.service.getContents(wtDocument);
ContentItem item = ContentHelper.getPrimary((FormatContentHolder) contentHolder);

if (item != null && item instanceof ApplicationData)
{
((ApplicationData) item).setFileName(newPrimaryContentName);
primaryContentNameUpdates++;
}



There are InfoEngine mechanisms to delete and/or add content items, however, I did not find any such mechanisms to simply rename the file name.



Any help would be appreciated.



Cory Skradski

1 reply

1-Visitor
October 19, 2012


Problem solved. I wasn't persisting the update. So, for anyone who is interested, here is the code snippet to update a primary content file name:


QuerySpec qs = new QuerySpec(WTDocument.class);


qs.appendWhere(new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.EQUAL, yourWTDocNumber), null);


QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
WTDocument wtDocument = (WTDocument) qr.nextElement();

ContentHolder contentHolder = ContentHelper.service.getContents(wtDocument);
ContentItem item = ContentHelper.getPrimary((FormatContentHolder) contentHolder);


if (item != null && item instanceof ApplicationData)
{
((ApplicationData) item).setFileName("new_file_name.xls");
PersistenceHelper.manager.save((ApplicationData) item);
}



Cory Skradski