Hi All,
I would like to implement a small program in Windchill where the Part Name and Part number will be written to a file (notepad) if its state has been changed.
Say for suppose if there is a Part A which is IN WORK state and if its life cycle state has been changed to PRODUCTION. We should then automatically write the name and number of the part to a notepad like
"Part A with number 00001 life cycle state has been changed from IN WORK TO PRODUCTION "
So how would we do that.
Can anyone help me in that ? Should we use any listener ? Can anyone tell the API or methods that has to be used for that ?
Thanks and Regards,
Aditya Achanta
Solved! Go to Solution.
Aditya,
Listener is final soultion i would use, since they may add somne performace issues in windchill.below are the two alternatives.
1. If you are using any worklfow process for releaing objects, then before releasing object from workflow write info in text file
2. You can add workflow on each state of lifecycle which will take PBO and write state info in file
Hope it helps !!!!
Thanks
Shreyas
Short Answer
You should be able to use a listener but off hand I don't know how to get the source transition state.
LifeCycleServiceEvent.generateEventKey(LifeCycleServiceEvent.STATE_CHANGE
The other alternative would be in a workflow.
Long Answer here is a rough example of the code putting it into a logger.info
You need 2 java class files
TransitionStateListenServiceInterface.java
package com.companynamehere.service.transitionstatelistener;
public interface TransitionStateListenServiceInterface {
}
TransitionStateListenService.java
import wt.util.WTPropertyVetoException;
import wt.lifecycle.*;
import wt.log4j.LogR;
import java.io.PrintWriter;
import java.io.Serializable;
import java.beans.PropertyVetoException;
import java.util.Enumeration;
import org.apache.log4j.Logger;
import wt.services.ManagerException;
import wt.services.ServiceEventListenerAdapter;
import wt.services.StandardManager;
import wt.session.SessionContext;
import wt.util.DebugProperties;
import wt.util.DebugWriter;
import java.util.Properties;
import wt.doc.WTDocument;
import wt.epm.EPMDocument;
import wt.fc.WTObject;
import wt.org.WTUser;
import wt.part.WTPart;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.util.WTContext;
import java.util.*;
public class TransitionStateListenService extends StandardManager implements TransitionStateListenServiceInterface, Serializable {
private static final String CLASSNAME = TransitionStateListenService.class.getName();
private static String FILE_SEPARATOR;
private static String WINDCHILL_HOME;
private static Logger logger = null;
public static PrintWriter print = null;
static {
try {
logger = LogR.getLogger(TransitionStateListenService.class.getName());
wt.util.WTProperties wtProperties = null;
wtProperties = wt.util.WTProperties.getLocalProperties();
FILE_SEPARATOR = System.getProperty("file.separator");
WINDCHILL_HOME = wtProperties.getProperty("wt.home", "");
} catch (Throwable throwable) {
logger.debug("\n" + throwable.getMessage());
}
}
@Override
public String getConceptualClassname() {
return CLASSNAME;
}
public static TransitionStateListenService newTransitionStateListenService() throws WTException {
TransitionStateListenService instance = new TransitionStateListenService();
instance.initialize();
return instance;
}
@Override
protected void performStartupProcess() throws ManagerException {
/* Standard debug output */
logger.debug(CLASSNAME + " performStartupProcess");
/* Standard way to become admin */
SessionContext prev = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
} catch (WTException wte) {
logger.error("StandardListenService: failed to set Administrator (ok if installation)");
return;
} finally {
SessionContext.setContext(prev);
}
try {
logger.debug("performStartupProcess() starting ..");
getManagerService().addEventListener(new ServiceEventListenerAdapter(this.getConceptualClassname()) {
@Override
public void notifyVetoableEvent(Object event) throws WTException, PropertyVetoException, WTPropertyVetoException {
LifeCycleServiceEvent lifecycleEvent = (LifeCycleServiceEvent) event;
Object object = lifecycleEvent.getEventTarget();
try
{
if (object instanceof WTPart) {
WTPart part = (WTPart) object;
// do your code here
logger.info("part " + part.getNumber().toString() + " " + part.getState().toString() );
}
}
catch(Exception e)
{
logger.error("error transitioning object" + object.toString() );
}
}
}, LifeCycleServiceEvent.generateEventKey(LifeCycleServiceEvent.STATE_CHANGE));
logger.info("performStartupProcess() Completed ..");
} catch (Exception e) {
logger.debug("Error in try block >>>>>>>>>" +e.getMessage());
throw new ManagerException("Error");
}
}
}
then you will need to add the following to site.xconf file
<Property name="wt.services.service.200000" overridable="true" targetFile="codebase/wt.properties" value="com.companynamehere.service.transitionstatelistener.TransitionStateListenServiceInterface/com.companynamehere.service.transitionstatelistener.TransitionStateListenService"/>
run xconfmanager -p
copy the class files their respective locations in the method server,
restart the server and you should be getting some logs.
Aditya,
Listener is final soultion i would use, since they may add somne performace issues in windchill.below are the two alternatives.
1. If you are using any worklfow process for releaing objects, then before releasing object from workflow write info in text file
2. You can add workflow on each state of lifecycle which will take PBO and write state info in file
Hope it helps !!!!
Thanks
Shreyas
I agree with Shreyas, I wouldn't dare to add a listener to a critical business object like part. The best approach is to use a vehicle object like change or promotion. You can add a robot to write the list of promotables or resultant objects to a file. Works clean - adding to that it is not a good practice to do set state as it does not leave a trail
Regards
Binesh Kumar
Medtronic - MITG
There are drawbacks and benefits to both solutions suggested and it will be up to the business to decide the impact.
Listener - PTC says these can/will impact performance if used excessively. That's the drawback, however it will also allow you to catch a "set state" which will not be caught in a workflow. If you really need to document EVERYTHING, you may need to consider the listener and take the performance hit.
Workflow - Less impact on the system and will allow you to get the state change in most cases. Will not catch a "set state".