Skip to main content

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

Popular posts from this blog

Understanding the Lock Mechanism in Pega

Now, let's delve into the Pega lock mechanism. To begin, Pega employs both database-level locks, which are of shorter durations (usually in milliseconds), and Pega-level locks, which extend over more extended periods (determined by user operations, often a few minutes). While you have the option to disable Pega-level locks using the Optimistic locking strategy (discussed later), database-level locks cannot be turned off; they are an integral part of the infrastructure layer. Moving forward, I'll elaborate on Pega-level locks. 1. Fundamentals of Pega-Level Locks When an individual initiates an assignment, the system transitions the state to "Perform" mode and acquires a lock. This lock data is then added to the "PR_SYS_LOCKS" table in the database, where it is systematically managed. Throughout this phase, no other user can access the same assignment. Upon the user's submission or cancellation of the assignment, the state shifts to "Review" mode...

Building a CSV File Download Function from a Page List

Consider a scenario where we want to download recently added table data from the screen into a CSV format for analysis. Today, we will explore how to accomplish this in Pega. An existing out-of-the-box activity named "pxConvertResultsToCSV" is available in the @baseclass, and you can utilize it without the need to create it from the ground up. The following example illustrates a sample screen: when the button is clicked, the Page List data on the screen is downloaded as a CSV file to the end user's local machine. 1.To begin, establish a Page List property. In this instance, I defined a Data class, "MyCo-Data-Item," and subsequently generated a Page List named "ItemList" in the Work class, referencing the Item class. 2.Position a table that references the Page List, and configure it to be inline-editable, allowing the addition of records directly from the screen. Additionally, position a button in close proximity to the table. 3.Configure the button by ...

How to set up JFrog Artifactory as a Repository in Pega.

Before delving into the topic, let's gain some understanding of what a repository is........... What is a repository? A repository is a centralized storage location where data, files, documents, or other digital assets are stored and managed. It serves as a single source of truth for organizing, versioning, and accessing these assets.  In the context of software development, a repository typically refers to a version control system, where developers store and manage source code, configuration files, documentation, and other project-related files. Version control systems like Git, Subversion (SVN), and Mercurial are commonly used repositories in software development. In addition to version control systems, repositories can also refer to databases, file systems, content management systems (CMS), or any other structured storage system used to manage digital assets. Overall, a repository provides a structured and organized way to store and manage digital assets, facilitating collaborat...