Writing a Validation
Advantage supports simple field references and more advanced scripting options within the expression that allow sites to utilize system capabilities to the full extent. Please note that implementors should be familiar with Advantage Framework and Application API to reference JAVA methods inside Advantage Framework classes. The following section explains different types of conventions supported within the expression in the Validation field on the Smart Suggestions Configuration page that helps implementors to define readable and maintainable expressions.
-
Field References
-
Constant Values
-
JAVA Methods
-
Business Object Instance Methods
-
Advantage Helper Class Methods
-
External JAVA Helper Classes Support
Field References
You can reference fields on the Business Object being validated simply by the name within the validation expression in the Validation field on the Smart Suggestions Configuration page. The Advantage application retrieves the field values and makes them available to the validation framework at run time.
Performance Budgeting ExamplePerformance Budgeting Example
For example, in Performance Budgeting, if a business object has a field named ’code’, then the rule expression should be able to refer to the field by name as shown below.
code == '010'
or
code != null
The following internal and external classes outside the advantage.jar module are supported to utilize extended helper functions within the expression.
|
Class Name |
Internal / External Package |
|---|---|
|
StringUtils |
org.apache.commons.lang3 |
For example, in Advantage Financial, if a business object has a field named FUND_CD, then the rule expression should be able to refer to the field by name as shown below.
FUND_CD == '010'
or
FUND_CD != null
To reference an old value of a field, simply add the “.old” prefix before the field name. To refer to the old Fund Code value in previous example, the expression should be:
old.FUND_CD == '020' and FUND_CD == '010'
Field values can be referenced via Advantage Framework provided JAVA methods using the “this” prefix as shown below and achieve the same result as above. It is highly recommended to use field references by name where possible to create readable and maintainable expressions.
this.getFUND_CD() == '010'
or
this.getData('FUND_CD').getString() == '010'
Constant Values
You can reference constants defined inside the Advantage classes within the expressions for comparisons. This will make expressions more readable. To use a constant in the expression in the Validation field on the Smart Suggestions Configuration page, you must be aware of JAVA class implementation and values mapped to constant labels inside the JAVA class.
Note: This is not applicable to Advantage Performance Budgeting.
To compare a field value with a constant, the following convention can be used within the expression in the Validation field on the Smart Suggestions Configuration page:
ACTIVE_FL == CVL_YES_NOImpl.YES
or
DOC_ACTN_CD == AMSCommonConstants.VALIDATE
JAVA Methods
You can refer to all public allowable JAVA methods inside the Business Object instance and public static methods in supported Advantage helper classes within the expression provided in the Validation field on the Smart Suggestions Configuration page. This may have an adverse impact when certain methods referenced within the expression change the state of data being validated while executing the expression. To prevent side effects, the Advantage application enforces additional checks and allows only certain method patterns in the expression assuming those methods are built using JAVA standards and are safe to use.
Note: This is not applicable to Advantage Performance Budgeting.
The Advantage application allows methods starting with the following patterns from Advantage classes to refer within the validation expression. This limitation is specifically for Advantage Helper:
-
get
-
has
-
is
-
does
-
check
-
chk
-
exist
-
strIsEmpty
-
strEqual
-
strInsensitiveEqual
-
addDays
-
addMonths
-
addYears
By default, Advantage supports reference of public static methods from all the Advantage helper classes inside the advantage.jar module. In addition to that, the following internal and external classes outside the advantage.jar module are supported to utilize extended helper functions within the expression.
|
Class Name |
Internal / External Package |
|---|---|
|
AMSCommonConstants |
com.amsinc.gems.adv.common |
|
AMSSecurity |
com.amsinc.gems.adv.common |
|
AMSSPARConstants |
com.amsinc.gems.adv.common |
|
StringUtils |
org.apache.commons.lang3 |
Business Object Instance Methods
To refer to business object instance JAVA methods within the expression in the Validation field on the Smart Suggestions Configuration page, simply use the method name with the “this” prefix.
Note: This is not applicable to Performance Budgeting.
For example, if the business object being validated has a method named getRunDate() that needs to be referenced in the validation expression, then the expression could be written as shown below:
this.getRunDate() < applicationDate
or
this.getRunDate() < EFFECTIVE_DT
Advantage Helper Class Methods
To refer to Advantage helper class methods (mostly static methods) in the Validation field on the Smart Suggestions Configuration page, simply use method invocation by providing required parameters.
Note: This is not applicable to Performance Budgeting.
For example, if advancing Effective Date by 5 days to compare with the Application Date or if advancing Effective Date by 2 years to compare with the End Date in validation:
AMSUtil.addDays( EFFECTIVE_DT, 5 ) < applicationDate
or
AMSUtil.addYears( EFFECTIVE_DT, 2 ) < END_DT
External JAVA Helper Classes Support
To refer to external Java helper class methods (like StringUtils from Apache commons library) in the Validation field on the Smart Suggestions Configuration page, simply use method invocation by providing required parameters.
For example, in Performance Budgeting, to check if String field is populated or blank in validation:
StringUtils.isBlank( code )
or
StringUtils.isBlank( name )
For example, in Financial, HRM, VSS, and Administration, to check if String field is populated or blank in validation:
StringUtils.isBlank( this.getFUND_CD() )
or
StringUtils.isBlank( FUND_NM )