when specific document created, we want to automatically create another document and attach as child
when specific document created, we want to automatically create another document and attach as child
In the given code the child document which created automatically its failed to add as a child, and i tried with without linkage. The document is created automatically but after i tried to link it was showing error
@Override
protected synchronized void performStartupProcess() throws ManagerException {
super.performStartupProcess();
System.out.println("Registering CreateDocumentListener listeners...");
final ManagerService managerService = this.getManagerService();
managerService.addEventListener(new ServiceEventListenerAdapter(CreateDocumentListenerManager.class.getName()) {
public void notifyVetoableEvent(Object event) throws Exception {
System.out.println("DocumentDownloadListener notifyVetoableEvent POST_STORE ");
CreateDocumentListenerManager.addChildDocument((KeyedEvent) event);
};
}, PersistenceManagerEvent.generateEventKey(PersistenceManagerEvent.POST_STORE));
}
protected static void addChildDocument(KeyedEvent event) throws WTException, PropertyVetoException, RemoteException {
Object eventTarget = event.getEventTarget();
if (eventTarget instanceof WTDocument) {
WTDocument doc = (WTDocument) eventTarget;
// Check if the created document is of type com.windchill.WFActivityA
TypeIdentifier type = ClientTypedUtility.getTypeIdentifier(doc);
if (type.getTypeInternalName().equals("com.windchill.WFActivityA")) {
// Get the name and number of the parent document
WTDocument doc1 = (WTDocument) doc;
// wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) doc1, "Check in comment");
WTDocumentUsageLink linknew = new WTDocumentUsageLink();
// Find the TypeIdentifier for com.windchill.WFActivityB
TypeDefinitionReference childTypeDefRef = TypedUtilityServiceHelper.service.getTypeDefinitionReference("com.windchill.WFActivityB");
System.out.println("childTypeDefRef :"+childTypeDefRef);
// Create a new document of type com.windchill.WFActivityB
WTDocument childDocument = WTDocument.newWTDocument();
childDocument.setName("Child Document " + doc1.getNumber());
WTDocumentMaster masterChild = (WTDocumentMaster)childDocument.getMaster();
// Set the type definition reference for the child document
childDocument.setTypeDefinitionReference(childTypeDefRef);
System.out.println("childDocument :"+childDocument);
linknew.setRoleAObject(doc1);
linknew.setRoleBObject(childDocument);
WTDocumentUsageLink usageLink = WTDocumentHelper.service.createUsageLink(doc1, childDocument);
wt.fc.PersistenceHelper.manager.save(usageLink);
wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) doc1, "Check in comment");
System.out.println("Created successfully !!");
}
}
}

