Hi, you can listen to the event
PersistenceManagerEvent.PRE_STORE
and then look for the MadeFromLink objects like:
@Override
public void notifyVetoableMultiObjectEvent(Object obj) throws WTException {
if (((KeyedEvent) obj).getEventType().equals(PersistenceManagerEvent.PRE_STORE)) {
WTCollection wtCollection = (WTCollection) ((PersistenceManagerEvent) obj).getEventTarget();
WTCollection madeFromLinkCollection = wtCollection.subCollection(MadeFromLink.class, true);
if (!madeFromLinkCollection.isEmpty()) {
log.debug("madeFromLinkCollection.size() = {}", madeFromLinkCollection.size());
Iterator iterator = madeFromLinkCollection.persistableIterator();
while (iterator.hasNext()) {
MadeFromLink madeFromLink = (MadeFromLink) iterator.next();
Persistable targetPersistable = madeFromLink.getCopy();
Persistable sourcePersistable = madeFromLink.getRoleBObject();
...
}
}
}
}
Not sure if there is a dedicated method for this.
If not, you can still navigate the link "wt.enterprise.MadeFromLink".
Thanks but seems its not working on 11.0 windchill version
It does work.
The following
PersistenceHelper.manager.navigate(myPart, "original", MadeFromLink.class, true)
returns the part that has been used to create "myPart".
So if there is no element in the QueryResult, it means myPart hasn't been created from a save-as.
But maybe that's not what you're looking for, if so, then elaborate your need.
Well, need is to identify whether WTPart being created via SAVE AS action on Create Part action. this need to be identify while creating WTPart e.g. on listener level. Post that rest validation will applied.
Currently am trying this on PersistenceManagerEvent.PRE_STORE listener service event.
tried your suggestion as well:
QueryResult qr=PersistenceHelper.manager.navigate( wtPart,"original", MadeFromLink.class, false);
this returns 0 elements.
This makes sense as the PRE_STORE event is (as its name means) is raised prior anything is stored in the DB, therefore you won't find the link.
I would rather look into the EnterpriseServiceEvent.PRE_COPY or VersionControlServiceEvent.NEW_VERSION or the PersistenceManagerEvent.INSERT events.
Or even implementing your own custom CopyWTPartDelegate
Hi, you can listen to the event
PersistenceManagerEvent.PRE_STORE
and then look for the MadeFromLink objects like:
@Override
public void notifyVetoableMultiObjectEvent(Object obj) throws WTException {
if (((KeyedEvent) obj).getEventType().equals(PersistenceManagerEvent.PRE_STORE)) {
WTCollection wtCollection = (WTCollection) ((PersistenceManagerEvent) obj).getEventTarget();
WTCollection madeFromLinkCollection = wtCollection.subCollection(MadeFromLink.class, true);
if (!madeFromLinkCollection.isEmpty()) {
log.debug("madeFromLinkCollection.size() = {}", madeFromLinkCollection.size());
Iterator iterator = madeFromLinkCollection.persistableIterator();
while (iterator.hasNext()) {
MadeFromLink madeFromLink = (MadeFromLink) iterator.next();
Persistable targetPersistable = madeFromLink.getCopy();
Persistable sourcePersistable = madeFromLink.getRoleBObject();
...
}
}
}
}