Skip to main content
10-Marble
July 25, 2024
Question

Workflow - How to Throw Warning Message to User

  • July 25, 2024
  • 2 replies
  • 2493 views

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);

2 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
July 26, 2024

Hi @marshall_brock 

I don't understand your question maybe. But have you tried to save the Boolean result to workflow variable? This way you can save the result and check if you need it, can't you?

.PetrH

10-Marble
July 30, 2024

I have tried using a workflow variable, both global and local to the activity. Perhaps it's a bug, but whenever I set the workflow variable and then throw the exception, the variable value is reverted. The activity transition code looked like the below, with "warningThrownVariable" being an example of the workflow variable.

 

START Transition:

//set warnings thrown variable to false at start of activity

warningThrownVariable = false;

 

COMPLETE TASK Transition:

//get warning message

String warningMessage = ext.customer.workflow.WorkflowHelper.executeBusinessRules(primaryBusinessObject);

//if warnings haven't been thrown, set warning thrown variable to true and throw warning message

if ( ! warningThrownVariable ) {

//this line to set warning thrown variable to true never seems to commit to memory  

warningThrownVariable = true;

  throw new WTException(warningMessage);

joe_morton
18-Opal
18-Opal
July 29, 2024

I might be missing something as well, but why not just use a workflow variable? You can initialize a Boolean in the workflow without needing to extend any classes or any of that. You can easily update the Boolean at any point in the workflow. 

10-Marble
July 30, 2024

Copied from my reply to the other response.

 

I have tried using a workflow variable, both global and local to the activity. Perhaps it's a bug, but whenever I set the workflow variable and then throw the exception, the variable value is reverted. The activity transition code looked like the below, with "warningVariable" being an example of the workflow variable.

 

START Transition:

//set warnings thrown variable to false at start of activity

warningThrownVariable = false;

 

COMPLETE TASK Transition:

//get warning message

String warningMessage = ext.customer.workflow.WorkflowHelper.executeBusinessRules(primaryBusinessObject);

//if warnings haven't been thrown, set warning thrown variable to true and throw warning message

if ( ! warningThrownVariable ) {

//this line to set warning thrown variable to true never seems to commit to memory  

warningThrownVariable = true;

  throw new WTException(warningMessage);

joe_morton
18-Opal
18-Opal
August 1, 2024

Ah, sorry I missed that other comment and response.

 

If I'm following your code, you always start with warningThrownVariable = false.

Somewhere else (not shown) it MAY get set to true.

But then if the variable is still false during task completion, you want to always set it to true?

 

Here's a couple of simple things to check (you probably already have done):

  • Check Syntax. Make sure there are no compile errors
  • Add system print lines in the if statement then check the logs to make sure the if statement is executing when you expect it to.
  • Make sure you've added the warningThrownVariable to the Workflow. 
  • Make sure you've added the warningThrownVariable to the Task, and that you've set it to Initialize From and Copy Into the Workflow variable