How to customize Guardrail warnings?

 In this article, I'll explain the process of personalizing Guardrail warnings by adding or removing them.

1.Customizing Guardrail warnings by adding your own.

Create an activity called "CheckForCustomWarnings" within the Rule class where you intend to include additional warnings. Differentiate it from the existing "CheckForWarnings," which is present in all Rule classes and cannot be overridden due to its Final status. For instance, if you aim to append warnings to a Flow action, establish this activity in the Rule-Obj-FlowAction class. Implement the following Java code and set up the When condition accordingly.


Following this implementation, if you leave the description of the Flow Action rule empty, the system will issue a severe warning as shown below.



2.Eliminate default(OOTB) Guardrail warnings.

While it is not advisable to remove the default warnings, as they serve to verify if the developer's code adheres to best practices, there might be exceptional cases where you may consider doing so. For instance, I recently identified an issue in the warning logic related to Obj-Browse. When specifying an optimized property under a Single Page for filtering, the system triggers a "pzObjBrowse-InvalidProp" SEVERE warning without a valid cause. This issue has been recognized as a product defect .While it can be justified temporarily, I prefer to eliminate it since it still contributes to the overall count of warnings.


In such scenarios, you have the option to suppress the warnings. Generate an activity named "CheckForCustomWarnings" within the Rule class from which you wish to eliminate warnings. In the given example, position it in the Rule-Obj-Activity class. Subsequently, implement the following Java code.

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



Substitute "pzObjBrowse-InvalidProp" with the specific warning name you intend to eliminate. If you wish to suppress multiple warnings, concatenate them using the || (OR) operator.

The Java code in the "(2) Remove out-of-the-box Guardrail warnings" section can be translated into an activity using the following implementation:


Notes:

1. In the first step, append the warnings to be removed to the page list.
2. In the second step, use a loop for each element in the value list ".pyTextValue".
   - In 2.2, employ a loop for each embedded page.
   - In 2.2, the condition is "@equals(.pxWarningName, Primary.pyNote)"; continue Whens on true, exit iteration on false.
3. Step 2.3 is identical to step 2.2, with only the Step page changed.
4. Instead of "Page-Remove," you can use "Property-Set" on ".pxWarningSeverity" to alter the warning level.


If your project opts to customize Guardrail warnings, I recommend doing so before your team commences the application development. This is because the CheckForCustomWarnings activity only affects new rules and does not impact rules created in the past. Warnings are stored in the rule instance's Blob, and the CheckForCustomWarnings activity is invoked only when saving the rule. The Guardrail gadget in Dev Studio examines the current state of rules and does not trigger the CheckForCustomWarnings activity. Therefore, if you wish to entirely eliminate warnings from past rules in locked lower rulesets, after creating the CheckForCustomWarnings activity, you should perform a "Save As" for the rules into higher rulesets. This will cause warnings in lower rulesets to disappear from the Guardrail gadget.


Happy Learning :)

Comments