Skip to main content
1-Visitor
March 17, 2017
Question

How to set state of objects back to the state when they started the workflow?

  • March 17, 2017
  • 1 reply
  • 4212 views

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?

1 reply

18-Opal
March 19, 2017

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.

dswomley1-VisitorAuthor
1-Visitor
March 20, 2017

The objects are on the same LifeCycle template.

1-Visitor
March 21, 2017

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

        }     

    }