Discussion
Pegasystems Inc.
JP
Last activity: 6 Jun 2023 5:49 EDT
How to customize (add or remove) Guardrail warnings
Hi,
In this post, I will share how to customize (add or remove) Guardrails warnings.
(1) Adding your custom Guardrail warnings
Create an activity named "CheckForCustomWarnings" in the Rule class where you want to add warnings to (don't be confused with "CheckForWarnings", which should already exist in all Rule classes. Since it is Final, you can never override it). For example, if you want to add warnings to Flow action, create it in Rule-Obj-FlowAction class. Write a Java code as below, and configure When condition.
After this implementation, if you leave description of flow action rule blank, system will give a severe warning as below.
(2) Remove out-of-the-box 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. For example, recently I have found a product issue in warning logic - when you do Obj-Browse, if you specify a property (optimized) under a Single Page for filtering, system throws "pzObjBrowse-InvalidProp" SEVERE warning for no reason. This was actually acknowledged as a product defect (INC-159925) and will be fixed in the future release. We can justify it for the time being, but I would rather want to eliminate it as it is still counted as warnings.
In such cases, you can suppress the warnings. Create an activity named "CheckForCustomWarnings" in the Rule class where you want to remove warnings from. For above example, place it in Rule-Obj-Activity class. Then write a Java code as below.
//Removing warning from page .pxWarnings
ClipboardProperty warningslist = myStepPage.getProperty(".pxWarnings");
for (int i = warningslist.size() ; i > 0; i--) {
ClipboardPage row = warningslist.getPageValue(i);
String s = row.getProperty(".pxWarningName").toString();
if (s.equals("pzObjBrowse-InvalidProp")) {
warningslist.remove(i);
}
}
//Removing warning from page .pxWarningsToDisplay
ClipboardProperty warningtodisplay = myStepPage.getProperty(".pxWarningsToDisplay");
for (int i = warningtodisplay.size() ; i > 0; i--) {
ClipboardPage row = warningtodisplay.getPageValue(i);
String s = row.getProperty(".pxWarningName").toString();
if (s.equals("pzObjBrowse-InvalidProp")) {
warningtodisplay.remove(i);
}
}
Replace "pzObjBrowse-InvalidProp" with the warning name that you want to get rid of. If you want to suppress multiple warnings, concatenate them by || (OR) operator.
- Notes
If your project decides to customize Guardrail warnings, I suggest that you do so before your team actually starts building application. This is because CheckForCustomWarnings activity acts on new rules, but it doesn't impact rules that are already created in the past. Warnings are stored in rule instance's Blob and CheckForCustomWarnings activity is only called when you save the rule. Guardrail gadget in Dev Studio looks at the current state of rules, and it doesn't call CheckForCustomWarnings. So, if you want to completely remove warnings from past rules in locked lower rulesets, after creating CheckForCustomWarnings activity, you should do Save As the rules into higher rulesets (warnings in lower rulesets will disappear from Guardrail gadget).
Hope this helps.
Thanks,