Skip to main content
1-Visitor
April 1, 2021
Solved

Routing/Tallying Expression in Assigned Activity

  • April 1, 2021
  • 1 reply
  • 6188 views

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

Best answer by d_graham

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

1 reply

18-Opal
April 16, 2021

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

1-Visitor
April 19, 2021

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

18-Opal
April 19, 2021

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