Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Solved! Go to Solution.
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,
I'm tying to use the PRE_COPY event to clear an IBA before the OIR so the IBA is set in the OIR even if it is a copy. This works fine when I do a Save As but for some reason it does not work for a Copy/Paste. The event is still fired but the OIR somehow picks upp the old value anyway. Just wanted to check if you had any insight to why this might be the case?
BR
Anders
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();
...
}
}
}
}