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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Resouce for workflow code writing

lgrant
15-Moonstone

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.

 

ACCEPTED SOLUTION

Accepted Solutions
BineshKumar1
13-Aquamarine
(To:lgrant)

        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
BineshKumar1
13-Aquamarine
(To:lgrant)

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

BineshKumar1
13-Aquamarine
(To:lgrant)

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 

 

 

BineshKumar1
13-Aquamarine
(To:lgrant)

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
15-Moonstone
(To:BineshKumar1)

Any idea what the error is?

 

error on CR.jpg

RandyJones
20-Turquoise
(To:lgrant)

You are missing a closing ')'

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

lgrant
15-Moonstone
(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
15-Moonstone
(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
15-Moonstone
(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.

BineshKumar1
13-Aquamarine
(To:lgrant)

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

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

Announcements

Top Tags