I'm trying set the state of all the objects attached to a promotion or CN back to the state when they started the workflow. The problem is the objects could have multiple starting states, either In Work or Development In work, so I can't use code to state state of every object attached to the promotion or CN. I was thinking to query the objects, which could be a combination of WTPart, WTDocument, and EPMDocuments, and maybe finding the maturity history of the latest revision, and setting the state to that initial revision. Problem is, I don't know how to do any of this. Has anyone experienced or written code to do something similar?
Drew,
Are the states in the same or different LifeCycle Templates?
If different you could get the template and determine which state is in it and then set to that state.
Easier yet, use a try-catch statement and try to set it to one of the states. If that fails catch it and set it to the other state.
This assumes of course that the states are not in both templates.
The objects are on the same LifeCycle template.
here's a method that takes a life cycle managed object and tries to set the state to first phase in life cycle.
Haven't tested it extensively but you can tweak it some more.
public void resetStateToFirst(LifeCycleManaged lcm) throws LifeCycleException, WTException{
LifeCycleTemplate template = (LifeCycleTemplate)lcm.getLifeCycleTemplate().getObject();
Vector<PhaseTemplate> v = (Vector<PhaseTemplate>) LifeCycleHelper.service.getPhaseTemplates(template);
Iterator<PhaseTemplate> it = v.iterator();
if (it.hasNext()) {
PhaseTemplate pt = (PhaseTemplate) it.next();
logger.debug("Setting state to: "+pt.getPhaseState());
LifeCycleHelper.service.setLifeCycleState(lcm, pt.getPhaseState());
}
}
this might work, but my problem is that the objects are possibly coming from not the first state of the life cycle (i.e. production in work)
the LC template is as follows:
Dev in Work || Under Review || Dev Released || Production In work || Under Review || Production Released
the problem is that they can attach objects from both dev in work and production in work to a CN and have them go to Production Released.... but if they go through a rework loop... then the objects have to go back to their initial states, which isn't always Dev in Work. hopefully this clarifies a little more.
Drew,
Have you looked at LifeCycleHelper.service.getHistory()
If not take a look. This method returns a QueryResult of LifeCycleHistory object for the LifeCycleManaged object passed to the method. The LCH objects have createstamps. You could compare the createstamp to the Promotion Request's createstamp to determine the appropriate state.
Also, is there an opportunity in your workflow to record the states. If yes, you could create a HashMap with the promotable and its corresponding state. The HashMap could be used later to set the state in the event the workflow is routed to rework.
I see, then the one thing you have may have to do is get the state of the objects as soon as they are attached to the CN as David suggested. Maybe save them in a HashMap object by creating a global HashMap map variable.
then in a workflow expression have something like:
WTChangeOrder2 cn = (WTChangeOrder2) primaryBusinessObject;
QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore(cn);
while qr.hasMoreElements(){
WTObject obj = (WTObject) qr.nextElement();
map.put(obj, obj.getLifeCycleState());
}
then at the end of the workflow reset objects based on information in that HashMap.