Skip to main content

Creating a custom guardrail warning

Guardrail warnings identify unexpected and possibly unintended situations, practices that are not recommended, or variances from best practices. You can create additional warnings that are specific to the organization's environment or development practices. Unlike rule validation errors, warning messages do not prevent the rule from saving or executing.

To add or modify rule warnings, override the empty activity called @baseclass.CheckForCustomWarnings. This activity is called as part of the Rule-.StandardValidate activity, which is called by, for example, Save and Save-As, and is designed to allow you to add custom warnings.

You typically want to place the CheckForCustomWarnings activity in the class of the rule type to which you want to add the warning. For example, if you want to add a custom guardrail warning to an activity, place CheckForCustomWarnings in the Rule-Obj-Activity class. Place the CheckForCustomWarnings activity in a ruleset available to all developers.

Configure the logic for checking if a guardrail warning needs to be added in the CheckForCustomWarnings activity. Add the warning using the default.pxAddGuardrailMessage function in the Pega-WB ruleset.

Removing or suppressing the default guardrail warnings

It is not recommended to remove the out-of-the-box warnings, as they are intended to check if developer's code is complying with good practices. However, in unusual circumstances you may want to do so. 

In such cases, you can suppress the warnings. Create an activity named CheckForCustomWarnings in the Rule class where you want to remove warnings from. When you customize CheckForCustomWarnings, follow the below two steps:

  1. Removal of class specific warnings
  2. Create an activity to remove common warnings across classes which will be included in CheckForCustomWarnings activity.

For example, if you want to remove the Pega Unit Warning for test case for an activity, place CheckForCustomWarnings activity in Rule-Obj-Activity class. In the Java step, write a Java code as below:

// Removing warnings from .pxWarnings page
ClipboardProperty warninglist = myStepPage.getProperty(".pxWarnings");
for (int i= warninglist.size(); i > 0; i--) {
  ClipboardPage row = warninglist.getPageValue(i);
  String wn = row.getProperty(".pxWarningName").toString();
    if (wn.equals("Pega Unit Warning")){
        warninglist.remove(i);
    }
}

// Removing warnings from .pxWarningsToDisplay page
ClipboardProperty warningdisplay = myStepPage.getProperty(".pxWarningsToDisplay");
for (int i= warningdisplay.size(); i > 0; i--) {
  ClipboardPage row1 = warningdisplay.getPageValue(i);
  String wdn = row1.getProperty(".pxWarningName").toString();
    if (wdn.equals("Pega Unit Warning")){
        warningdisplay.remove(i);
    }
}

Note: It is not a best practice to suppress rule warnings to improve your application guardrail compliance score.

This Topic is available in the following Module:

If you are having problems with your training, please review the Pega Academy Support FAQs.

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 Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice