cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

how to identify WTPart being created using SAVE AS action ?

shetakesubhash7
6-Contributor

how to identify WTPart being created using SAVE AS action ?

 
1 ACCEPTED SOLUTION

Accepted Solutions

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();
...
}
}
}
}

 

View solution in original post

7 REPLIES 7
Florent
14-Alexandrite
(To:shetakesubhash7)

Not sure if there is a dedicated method for this.

If not, you can still navigate the link "wt.enterprise.MadeFromLink".

Florent ROUSSEL
www.4cad.ca

Thanks but seems its not working on 11.0 windchill version

Florent
14-Alexandrite
(To:shetakesubhash7)

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.

 

Florent ROUSSEL
www.4cad.ca

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. 

 

 

 

Florent
14-Alexandrite
(To:shetakesubhash7)

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

Florent ROUSSEL
www.4cad.ca

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();
...
}
}
}
}

 

Top Tags