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

We are happy to announce the new Windchill Customization board! Learn more.

Routing/Tallying Expression in Assigned Activity

SvenVanDroogenb
7-Bedrock

Routing/Tallying Expression in Assigned Activity

Hi,

 

We have the following Routing/Tallying Expression in an Assigned Activity to avoid time loss during a multiple mandatory user review task:

 

int number=wt.workflow.work.WfTally.count(self,"Rework");
if(number>0)
   {
   result = "Rework";
   wt.workflow.work.WorkflowHelper.service.completeActivity(self,"Rework");
   }
else
   {
   result = "Approve";
   }

 

How can I update this Expression if I want to include 2 extra Routing Options (Revise, Cancel)?

All mandatory Reviewers must Approve to release the Object in Review.  If any Reviewer chooses another option, the flow should immediate start to follow that Routing Option, even if one or more Reviewers already approved.

 

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions

Sven,

 

Correct me if I misunderstand but what you have is an activity that gets routed to several users.

To proceed along approved path all the users need to route to Approve.  However, if any user routes to Rework, Revise or Cancel you want the workflow to immediately proceed along the selected path.

Correct?

 

If I understand you correctly do the following.

In the Transition tab (NOT the Routing tab) select the "Complete Task" transition and enter:

 

String[] options = {"Rework", "Revise", "Cancel"};

 

for (String option : options) {

   if (wt.workflow.work.WfTally.count(self, option) > 0) {
 wt.workflow.work.WorkflowHelper.service.completeActivity(self, option);

  }
}

 

That's all you need.  Again, this is in the Transition tab NOT the Routing tab.

Note that you need no mention of "Approve".  You want the workflow to work normally unless someone routes to Rework, Revise or Cancel. Only then do you complete the workflow activity and proceed along that routing path.

 

David

View solution in original post

10 REPLIES 10

Sven,

Try this:

 

String result = null;

String[] options = {"Rework", "Revise", "Cancel"};

 

for (String option : options) {

   if (wt.workflow.work.WfTally.count(self, option) > 0) {
   result = option;

   break;

   }

}

 

if (result != null) {
   wt.workflow.work.WorkflowHelper.service.completeActivity(self,result);
   } else {
   result = "Approve";
   }

 

This should get the job done.

It's also easily scalable.  If you need to add or remove a routing option you just need to edit the String[] array accordingly.

 

David

Hi David,

Thanks for your help.  I tried your code but received the following syntax errors:


C:\ptc\Windchill\temp\WfExpression37156969.java:26: error: variable result is already defined in method executemethod_1(Object[],Object[])
String result = null;
       ^
C:\ptc\Windchill\temp\WfExpression37156969.java:38: error: incompatible types: Object cannot be converted to String
   wt.workflow.work.WorkflowHelper.service.completeActivity(self,result);
                                                                 ^
Note: C:\ptc\Windchill\temp\WfExpression37156969.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors

 

Any idea what went wrong?

Kr,

Sven

Sven,

 

Yes, I do.

result is already defined so just change:

String result = null;

to

result = null;

 

result is probably null when the code starts so you might not need the result = null; statement.

 

David

Hi David,

 

Is it possible the String option solution can't be used due to the fact that the Routing variables are of Object type?

 

Kr,

Sven

Sven,

 

That would be true if result is an Object.

in that case you need to cast result to a String.

 

So just add (String) in front of result in the method that is completing the activity.

wt.workflow.work.WorkflowHelper.service.completeActivity(self, (String) result);

 

This is needed because a String is an Object but an Object isn’t necessarily a String therefore cast the Object to a String and the code will compile.

 

The more I think about it you could probably simplify the code a bit more.

The code below should complete the activity and route to Rework, Revise or Cancel if any of the three are the selected routing option. If none are then result is set to Approve.

 

String[] options = {"Rework", "Revise", "Cancel"};

 

for (String option : options) {

   if (wt.workflow.work.WfTally.count(self, option) > 0) {
 wt.workflow.work.WorkflowHelper.service.completeActivity(self, option);

  }
}

 

result = “Approve”;

 

Let me know how it goes.

 

David

Hi David,

Thanks again for your help.  Both codes compiled without error, but they both don't have the expected result in the workflow: every participant still needs to complete his review tasks before the flow continues.

Kr,

Sven

Sven,

 

Where are you putting the code?

Which transition?

Hi David,

The code is used in the Routing section of an Assigned Activity of a Workflow.
See attached screenshot.

 

Kr,
Sven

Sven,

 

Correct me if I misunderstand but what you have is an activity that gets routed to several users.

To proceed along approved path all the users need to route to Approve.  However, if any user routes to Rework, Revise or Cancel you want the workflow to immediately proceed along the selected path.

Correct?

 

If I understand you correctly do the following.

In the Transition tab (NOT the Routing tab) select the "Complete Task" transition and enter:

 

String[] options = {"Rework", "Revise", "Cancel"};

 

for (String option : options) {

   if (wt.workflow.work.WfTally.count(self, option) > 0) {
 wt.workflow.work.WorkflowHelper.service.completeActivity(self, option);

  }
}

 

That's all you need.  Again, this is in the Transition tab NOT the Routing tab.

Note that you need no mention of "Approve".  You want the workflow to work normally unless someone routes to Rework, Revise or Cancel. Only then do you complete the workflow activity and proceed along that routing path.

 

David

Thanks a lot David!  This is exactly what we needed.

Kr,

Sven

Top Tags