Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

How to specify error message text within the Java code of an edit validate rule

Updated on May 3, 2020

Summary

A developer asks: I want to learn the best way to present friendly, meaningful error messages for invalid property values.

Our application includes a flow action that allows users to specify a list of dates entered into Date-Calendar-formatted properties.  The properties use the standard edit validate rule named IsValidDate.  This has the advantage that validation occurs every time a user submits the flow action.  A red X appears with the tooltip:

Invalid date specified for IsValidDate.

However, users would like a friendlier error message, one that refers them to the correct date format.

Rule-Message rules are designed to allow configurable messages.  What is the best way to associate a Rule-Message with a Rule-Edit-Validate rule?   We could use a Rule-Obj-Validate rule,but that needs to be called from within an activity.  This would require that we create at least two more rules just to change an error message. 

We tried the calling the PublicAPI function theProperty.addMessage() to pass a (optionally parameterized) Rule-Message into the error message that is returned from the Java in the Rule-Edit-Validate.  However, this function adds a second Rule-Message text to the property; it doesn't alter the above message. 


 

 

Suggested Approach

The error message that appears when a property fails to pass a Rule-Edit-Validate rule is always from the Rule-Message named PropertyInfo-EditValidate.   You cannot override this message.

However, when writing an edit validate rule, you can access the property value being edited through the ClipboardProperty Java variable named theProperty.  Two other Java variables established are:

  • theValue —the String value of the property
  • itsType — a char representing the type of the property (one of the constants from PropertyInfo TYPE_*. 

Therefore, your Java code can add an additional message to the property . 

This is the best way to tailor the message.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us