Workflow - How to Throw Warning Message to User
Version: Windchill 12.1
Use Case: I'm attempting to throw a warning message to users when they hit "Complete Task" from a workflow activity when specific criteria is hit, with the goal being that the message is thrown once and then can be bypassed.
Description:
I have created a class on the application server called WorkflowHelper that has a private instance variable that gets initialized (if not already) whenever any workflow starts. It has a HashMap associated with it that stores the Change Task number as a key with a boolean "warnings thrown" value to indicate whether the warning message has been thrown once or not.
The issue is that the code executed during the workflow transitions to set the boolean value to "true" once the warning is thrown is not saved to memory until either the workflow is terminated or the activity is completed. This causes the warning to be continually thrown during the activity and never properly updated, and also prevents the user from bypassing the warning, effectively making it an error.
For reference, psuedo code from the activity in question is outlined below.
START Transition:
//gets instance of workflow helper and sets warnings thrown to false when activity is started
ext.customer.workflow.WorkflowHelper wfh = ext.customer.workflow.WorkflowHelper.getInstance();
wfh.setWarningsThrownFalse(primaryBusinessObject);
COMPLETE TASK Transition:
//get instance of workflowhelper
ext.customer.workflow.WorkflowHelper wfh = ext.customer.workflow.WorkflowHelper.getInstance();
//return string containing the warning message if business rule criteria is not met, takes PBO and boolean input of whether warnings have been thrown or not. Boolean is never properly updated to "true" until workflow is terminated or activity completes.
String warningMessage = ext.customer.workflow.WorkflowHelper.executeBusinessRules(primaryBusinessObject, wfh.getWarningsThrown(primaryBusinessObject));
//if warning message isn't empty, throw message to user. it will return empty if boolean input value is true.
if ( ! warningMessage.isEmpty() ) {
wfh.setWarningsThrownTrue(primaryBusinessObject);
throw new WTException(warningMessage);
}

