cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Resouce for workflow code writing

lgrant
14-Alexandrite

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

12 REPLIES 12

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();
        }
lgrant
14-Alexandrite
(To:BineshKumar1)

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

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 

 

 

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 

Since the "lock" method is well-proven over many releases for Promotion, would definitely be best to utilize that approach if at all possible.

 

lgrant
14-Alexandrite
(To:BineshKumar1)

Any idea what the error is?

 

error on CR.jpg

RandyJones
17-Peridot
(To:lgrant)

You are missing a closing ')'

if(state.equalsIgnoreCase("INWORK")) <---------

lgrant
14-Alexandrite
(To:RandyJones)

After adding in the missing )

I now have a new list of errros.

Checking Syntax...
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:59: error: cannot find symbol
QueryResult affectedObjects = wt.change2.ChangeHelper2.service.getChangeables((wt.change2.ChangeRequestIfc) changeRequest, true);
^
symbol: class QueryResult
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:61: error: cannot find symbol
LifeCycleManaged object = (LifeCycleManaged)affectedObjects.nextElement();
^
symbol: class LifeCycleManaged
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:61: error: cannot find symbol
LifeCycleManaged object = (LifeCycleManaged)affectedObjects.nextElement();
^
symbol: class LifeCycleManaged
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:65: error: cannot find symbol
LifeCycleHelper.service.setLifeCycleState (object, State.toState ("UNDERREVIEW"));
^
symbol: variable State
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:65: error: package LifeCycleHelper does not exist
LifeCycleHelper.service.setLifeCycleState (object, State.toState ("UNDERREVIEW"));
^
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:68: error: cannot find symbol
} catch (WTException e) {
^
symbol: class WTException
location: class WfExpression332772435
Note: /opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
Syntax check complete.

BenPerry
12-Amethyst
(To:lgrant)

In the workflow Execute Expression robots, you need to use full path of the java classes & methods.  So instead of just LifeCycleManaged, use wt.lifecycle.LifeCycleManaged.  Same with LifeCycleHelper.

 

I think you still have some more errors to fix, but this will reduce a little.  Then you can focus on what is left.

lgrant
14-Alexandrite
(To:BenPerry)

few less errors. Community project at its best 🙂

Checking Syntax...
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:59: error: cannot find symbol
QueryResult affectedObjects = wt.change2.ChangeHelper2.service.getChangeables((wt.change2.ChangeRequestIfc) changeRequest, true);
^
symbol: class QueryResult
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:61: error: cannot find symbol
wt.lifecycle.LifeCycleManaged object = (LifeCycleManaged)affectedObjects.nextElement();
^
symbol: class LifeCycleManaged
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:65: error: cannot find symbol
wt.lifecycle.LifeCycleHelper.service.setLifeCycleState (object, State.toState ("UNDERREVIEW"));
^
symbol: variable State
location: class WfExpression332772435
/opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java:68: error: cannot find symbol
} catch (WTException e) {
^
symbol: class WTException
location: class WfExpression332772435
Note: /opt/ptc/Windchill_9.0/Windchill/tmp/WfExpression332772435.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
Syntax check complete.

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

View solution in original post

lgrant
14-Alexandrite
(To:BineshKumar1)

Now that is what the cummunity page is for. Thanks everyone.

Announcements