Skip to main content
16-Pearl
August 14, 2017
Solved

Resouce for workflow code writing

  • August 14, 2017
  • 1 reply
  • 7050 views

I am in need of a resource for workflow code writing?

We are on Windchill PDMLink 11, M020

Nothing very complicated.

On a CR, I need a bit of code that would:

If primaryBusinessObject = INWORK then set sate UNDERREVIEW, else do nothing.

 

Any item on a CR that is submitted that is in a In Work state should be set to Under Review. If it's not in a state of In Work then do nothing to that item.

I would then also need to back that out again on a rework loop. If its Under Review then set to In Work, if its anything else then do nothing to that item.

 

Best answer by BineshKumar1
 try {
 wt.change2.WTChangeRequest2 changeRequest = (wt.change2.WTChangeRequest2) primaryBusinessObject;
 //Query & loop through the change request to get all the changeables
 wt.fc.QueryResult affectedObjects = wt.change2.ChangeHelper2.service.getChangeables((wt.change2.ChangeRequestIfc) changeRequest, true);
 while(affectedObjects.hasMoreElements()) {
 wt.lifecycle.LifeCycleManaged object = (wt.lifecycle.LifeCycleManaged)affectedObjects.nextElement();
 String state = object.getLifeCycleState().toString();
 // if the lifecycle state is design, set it to release review or else do nothing.
 if(state.equalsIgnoreCase("INWORK")) {
 wt.lifecycle.LifeCycleHelper.service.setLifeCycleState (object, wt.lifecycle.State.toState ("UNDERREVIEW"));
 }

 }


 } catch (wt.util.WTException e) {
 e.printStackTrace();
 }

1 reply

1-Visitor
August 15, 2017

The easiest option would be to define the lock state and use the Method  transitionTargets(Object theObject, Transition transition, boolean failIfNoTransitionExists) to set the affected objects to a lock state defined by LC template. But I am not sure, whether this work for CR, I have used this for CN.

 

 try {
 WTChangeRequest2 changeRequest = (wt.change2.WTChangeRequest2) primaryBusinessObject;
 //Query & loop through the change request to get all the changeables
 QueryResult affectedObjects = wt.change2.ChangeHelper2.service.getChangeables((wt.change2.ChangeRequestIfc) changeRequest, true);
 while(affectedObjects.hasMoreElements()) {
 LifeCycleManaged object = (LifeCycleManaged)affectedObjects.nextElement();
 String state = object.getLifeCycleState().toString();
 // if the lifecycle state is design, set it to release review or else do nothing.
 if(state.equalsIgnoreCase("design") {
 LifeCycleHelper.service.setLifeCycleState (object, State.toState ("RELEASE_REVIEW"));
 }

 }


 } catch (WTException e) {
 e.printStackTrace();
 }
lgrant16-PearlAuthor
16-Pearl
August 15, 2017

For that to work, each object type we manage (wtPart, EPMdocument, etc.) would need to have lock selected at In Work ?

Lock.jpg

 

 

 try {
            WTChangeRequest2 changeRequest = (wt.change2.WTChangeRequest2) primaryBusinessObject;
            //Query & loop through the change request to get all the changeables
            QueryResult affectedObjects = wt.change2.ChangeHelper2.service.getChangeables((wt.change2.ChangeRequestIfc) changeRequest, true);
            while(affectedObjects.hasMoreElements()) {
                LifeCycleManaged object = (LifeCycleManaged)affectedObjects.nextElement();
                String state = object.getLifeCycleState().toString();
                // if the lifecycle state is INWORK, set it to UNDERREVIEW or else do nothing.
                if(state.equalsIgnoreCase("INWORK") {
                    LifeCycleHelper.service.setLifeCycleState (object, State.toState ("UNDERREVIEW"));
                }

}

} catch (WTException e) {
            e.printStackTrace();
        }

1-Visitor
August 16, 2017

That's correct. But I am not sure whether lock method works for Change Request. It works for change notice, change task or even promotion request.

The code which had in my previous post will work without any lock transition