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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Workflow: to popup if criteria are not correct before completing an activity

HenriMarchal
1-Newbie

Workflow: to popup if criteria are not correct before completing an activity

Hello,

I've got an activity in a workflow where the user has to fill some textbox and other things. These criteria must follow a validation rule.

I know how to check the criteria once the activity is complete, but it is too late because if the criteria are not ok the activity shouyldn't be validated.

The best should be to launch the validation when the user clicks "complete activity", and if the criteria are wrong, to popup an error message and to stop the "complete activity" process. So the user stay in the activity and must change the criteria.

How could I proceed ?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions

We do this all the time - and it should be built into pretty much all workflow activities.

The key is to use the Transitions tab of the Activity, adding a snippet of Java code to selected Transition(s). There is very little documented from PTC on this. Let us know if interested in further info.

One small example. In this case, we require that the user enter a number into a blank, and the number cannot be negative. This code is on the Complete transition. The variable (defined prior to this) is: rndhours.

if(rndhours<1)
{throw new wt.util.WTException(new Throwable(new String("R&D hours must be greater than 0!")));}

Further on in another activity, we require that another number be between 0 and 100. This variable is: PercentDone.

if(PercentDone<0||PercentDone>99)
{throw new wt.util.WTException(new Throwable(new String("Percent Done must be between 0 and 99.\nIf this request is 100 percent done select close.")));}

In all cases, the user cannot Complete Task - the popup window must be acknowledged and the user needs to address the requirement.

View solution in original post

2 REPLIES 2

We do this all the time - and it should be built into pretty much all workflow activities.

The key is to use the Transitions tab of the Activity, adding a snippet of Java code to selected Transition(s). There is very little documented from PTC on this. Let us know if interested in further info.

One small example. In this case, we require that the user enter a number into a blank, and the number cannot be negative. This code is on the Complete transition. The variable (defined prior to this) is: rndhours.

if(rndhours<1)
{throw new wt.util.WTException(new Throwable(new String("R&D hours must be greater than 0!")));}

Further on in another activity, we require that another number be between 0 and 100. This variable is: PercentDone.

if(PercentDone<0||PercentDone>99)
{throw new wt.util.WTException(new Throwable(new String("Percent Done must be between 0 and 99.\nIf this request is 100 percent done select close.")));}

In all cases, the user cannot Complete Task - the popup window must be acknowledged and the user needs to address the requirement.

Like Mike said, do your validation and throw a WTException in the approproate transition - probably Complete - of the activity template.

Keep in mind that there are a few possible problems with this. You'd need to test, but I *think* the following few statements are true.

1. If recording variable changes, wfdataeventaudits are created even if you throw an Exception

2. If recording signatures, signatures are created even if you throw an Exception

3. If multiple people are completing the activity, they each have their own workitem, and the transition only fires when the last person completes the activity.

Do your research. Test it well.

Top Tags