Skip to main content
16-Pearl
Aug 14, 2017 6:48 PM UTC
Solved

Resouce for workflow code writing

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.

 

2-Explorer
Aug 18, 2017 2:54 PM UTC
 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();
 }

12 replies

2-Explorer
Aug 15, 2017 12:09 PM UTC

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();
 }
Translate
lgrant16-PearlAuthor
16-Pearl
Aug 15, 2017 2:36 PM UTC

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

Translate
2-Explorer
Aug 16, 2017 2:33 AM UTC

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 

 

 

Translate