Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
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 !!");
}
}
}
Hi @AR_9920456
What is the error you are talking about?
The point could be that the original Document is not yet stored and listener event is triggered too early.
PetrH
I am unable to do save as the EPM Document. while save as its giving error in MS log
Error Message : "The value of "Owner Application" cannot be set to null, since it is a "required" attribute."
Sorry,this is the code iam using.
In this line error is poping up [ copyInfoArray = EnterpriseHelper.service.newMultiObjectCopy(originals); ]
private EPMDocument saveAsCADAssembly(EPMDocument emptyCADAssembly , String name, String number) {
try {
RevisionControlled[] originals = new RevisionControlled[1];
CopyObjectInfo[] copyInfoArray = null;
originals[0] = emptyCADAssembly;
System.out.println("originals: " + originals);
copyInfoArray = EnterpriseHelper.service.newMultiObjectCopy(originals);
EPMDocument copy = (EPMDocument) copyInfoArray[0].getCopy();
copy.setNumber(number +".SLDASM");
System.out.println("number set");
copy.setName(name+".SLDASM");
System.out.println("name set");
copy.setContainer(emptyCADAssembly.getContainer());
copyInfoArray = EnterpriseHelper.service.saveMultiObjectCopy(copyInfoArray);
} catch (Exception e) {
e.printStackTrace();
}