AgileApps Support Wiki Pre Release

Difference between revisions of "Validations"

From AgileApps Support Wiki
imported>Aeric
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Designer > Rules & Processes > Validations'''
'''[[File:GearIcon.png]] > Customization > Objects > {object} > Validations'''


When a telephone number in your database has too many digits, it is bad information, and it slows you down. Clean data is essential to efficient performance. Data validation policies help to avoid simple mistakes, and assure that the data entering your system is sound.  
When a telephone number in your database has too many digits, it is bad information, and it slows you down. Clean data is essential to efficient performance. Data validation policies help to avoid simple mistakes, and assure that the data entering your system is sound.  


Validation policies let you establish triggering actions, custom criteria, and error messages that are activated when data changes. They are an essential part of [[Workflows]], especially when used in conjunction with [[Data Policy|Data Policies]].
Validation policies let you establish triggering actions, custom criteria, and error messages that are activated when data changes.


Validation policies compare field data using formulas you create - the result is a true or false value. When the return value is true, no action is taken. When false, the system displays a custom error message (see [[#Example|Example]]).
Validation policies compare field data using formulas you create - the result is a true or false value. When the return value is true, no action is taken. When false, the system displays the error message you specify.


==Sample Validation==
==Sample Validation==
Line 14: Line 14:
=== Create the Validation Criteria ===
=== Create the Validation Criteria ===


For the validation criteria, enter a [[Formula Expressions|Formula Expression]]. Functions are available for all data types: date, logical, math and text. The expression you develop to create a validation policy can contain multiple fields to validate, such as ensuring that phone numbers do not exceed 10 digits or names do not contain invalid characters.
For the validation criteria, enter a [[Formula Expressions|Formula Expression]]. Available function types include date, logical, math, and text. The expression you develop to create a validation policy can contain multiple fields to validate, such as ensuring that phone numbers do not exceed 10 digits or names do not contain invalid characters.


===Add a Data Validation Policy to an Object===
=== Validate Incoming Object Data ===


#Click '''Designer > Data > Objects > {object} > Validations'''
#Click '''[[File:GearIcon.png]] > Customization > Objects > {object} > Validations'''
#Enter a Name for the validation policy
#Enter a Name for the validation policy
#To enable the policy, click the Enable checkbox
#To enable the policy, click the Enable checkbox
Line 25: Line 25:
#*Update
#*Update
#*Delete
#*Delete
#Enter an [[Expressions|Expression]] in the Validation Criteria section. The expression must evaluate to true or false. Define the condition(s) that record data must meet to trigger the validation policy. Learn more: [[Formula Expressions]]
#Enter an [[Expressions|Expression]] in the '''Validation Criteria''' section. To trigger a validation error, the expression must evaluate to <tt>false</tt>.  
#;Field:The field that must contain the condition. All fields contained in this object are listed.
#: ''Tip:'' It is often easier to create the expression that defines ''valid'' data. Put the entire expression in parentheses, and add ''not''.
#;Operator:Choose an operator to build an expression
#: For example: ''<tt>!(...valid-data expression here...)</tt>'', where "''<tt>!</tt>''" = "not".
#Choose [[:Category:Formula_Functions|Function]]
#: ''Learn more: ''[[Formula Expressions]]
#*Select the type of function, the specific function to use, and click the Insert button. The types of functions are:
##Field:The field that must contain the condition. All fields contained in this object are listed.
#**Date Functions
##Operator:Choose an operator to build an expression
#**Logical Functions
##Click [[:Category:Formula_Functions|Function]]
#**Math Functions
##*Select the type of function, the specific function to use, and click the Insert button. The types of functions are:
#**Text Functions
##**Date Functions
#Click the Check Syntax button to validate the expression.
##**Logical Functions
#Enter the Error Message that you want to appear if the data causes an error condition in the validation policy.
##**Math Functions
##**Text Functions
#Click the '''[Check Syntax]''' button to validate the expression.
#To display the error message at a field level, you can provide the values in the '''Set field level display for error message''' section.
#*Click '''Choose Field''' and select the desired field.
#*Enter the desired error message for the selected field.
#*You can use the following options to manage the error messages for specific fields:
#**'''Add''': To add the error message for a field.
#**'''Delete''': To delete the error message for a field.
#**'''Reset''': To reset the error message for a field.
#To display the error message at the top level, you can provide the values in the '''Error Message''' section.
{{Note| If you have provided values in both '''Set field level display for error message''' and '''Error Message''' sections, then the preference is always given to the field level display of error message.}}


==Sophisticated Validations using Java Code==
== Complex Validation and Data Formatting ==
It is often useful, for example, to allow a phone number to be entered in multiple formats, but store it in a common format. In such situations, you want to re-format the data that has been entered before validating it. Or you may have validation policies that depend on complex factors that aren't easily expressed, or that need to be reused in multiple forms.


Validation policies make it easy to compare a data value against a known quantity. But more sophisticated validations require Java programming. For example:
For such situations, there are two options:
:* Inspect a string to validate format of a credit card number or social security number
:* '''Field and Form scripts'''
:* Lookup lower and upper limits in a data table, using a customer code of some kind.
:: A field script can indicate that data is invalid before data is saved.
:: A form 'On Save' script can surround a field that is missing data with a red box.
:: But they only work for data entered using that form. They don’t validate data entered using an API.
::: '''Tip:''' To use a script in multiple forms, upload it as a static resource
::: [[Static Resources#Accessing a JavaScript Resource from an Object Form]]


For sophisticated validations of that kind, use a [[Data Policy]]. In particular, see the
:* '''Add/update rules'''
[[Invoke_a_Java_Method_From_a_Data_Policy#Example:_Validate_Incoming_Data|Data Policy Example:Validate Incoming Data]].
:: An add/update rule checks the data before it is stored in the database.
:: It works for APIs as well as forms. But it doesn’t do as a good a job of highlighting the problems.
:: The rule can compare fields directly and invoke Java code that throws an exception.
:: Or the Java code can do the validation (allowing it to be reused elsewhere).
:: ''Learn more:'' [[Event Rules]]
<noinclude>
<noinclude>


[[Category:Rules & Processes | 5]]
[[Category:Object Aspects]]
[[Category:Objects| 7]]
[[Category:{{features}}]]
[[Category:Glossary]]
</noinclude>
</noinclude>

Latest revision as of 11:04, 20 May 2024

GearIcon.png > Customization > Objects > {object} > Validations

When a telephone number in your database has too many digits, it is bad information, and it slows you down. Clean data is essential to efficient performance. Data validation policies help to avoid simple mistakes, and assure that the data entering your system is sound.

Validation policies let you establish triggering actions, custom criteria, and error messages that are activated when data changes.

Validation policies compare field data using formulas you create - the result is a true or false value. When the return value is true, no action is taken. When false, the system displays the error message you specify.

Sample Validation

You might check that a telephone number entered in a data field has the correct number of digits. If the number of digits is not equal to 10, an error message is displayed, and the process stops until the correction is made.

While this is a simple example of data validation, you can easily create complex and powerful validation formulas with the available picklists.

Create the Validation Criteria

For the validation criteria, enter a Formula Expression. Available function types include date, logical, math, and text. The expression you develop to create a validation policy can contain multiple fields to validate, such as ensuring that phone numbers do not exceed 10 digits or names do not contain invalid characters.

Validate Incoming Object Data

  1. Click GearIcon.png > Customization > Objects > {object} > Validations
  2. Enter a Name for the validation policy
  3. To enable the policy, click the Enable checkbox
  4. Choose a Triggering Action. The data validation policy will be applied when one of these actions is applied to the record:
    • Add
    • Update
    • Delete
  5. Enter an Expression in the Validation Criteria section. To trigger a validation error, the expression must evaluate to false.
    Tip: It is often easier to create the expression that defines valid data. Put the entire expression in parentheses, and add not.
    For example: !(...valid-data expression here...), where "!" = "not".
    Learn more: Formula Expressions
    1. Field:The field that must contain the condition. All fields contained in this object are listed.
    2. Operator:Choose an operator to build an expression
    3. Click Function
      • Select the type of function, the specific function to use, and click the Insert button. The types of functions are:
        • Date Functions
        • Logical Functions
        • Math Functions
        • Text Functions
  6. Click the [Check Syntax] button to validate the expression.
  7. To display the error message at a field level, you can provide the values in the Set field level display for error message section.
    • Click Choose Field and select the desired field.
    • Enter the desired error message for the selected field.
    • You can use the following options to manage the error messages for specific fields:
      • Add: To add the error message for a field.
      • Delete: To delete the error message for a field.
      • Reset: To reset the error message for a field.
  8. To display the error message at the top level, you can provide the values in the Error Message section.

Notepad.png

Note: If you have provided values in both Set field level display for error message and Error Message sections, then the preference is always given to the field level display of error message.

Complex Validation and Data Formatting

It is often useful, for example, to allow a phone number to be entered in multiple formats, but store it in a common format. In such situations, you want to re-format the data that has been entered before validating it. Or you may have validation policies that depend on complex factors that aren't easily expressed, or that need to be reused in multiple forms.

For such situations, there are two options:

  • Field and Form scripts
A field script can indicate that data is invalid before data is saved.
A form 'On Save' script can surround a field that is missing data with a red box.
But they only work for data entered using that form. They don’t validate data entered using an API.
Tip: To use a script in multiple forms, upload it as a static resource
Static Resources#Accessing a JavaScript Resource from an Object Form
  • Add/update rules
An add/update rule checks the data before it is stored in the database.
It works for APIs as well as forms. But it doesn’t do as a good a job of highlighting the problems.
The rule can compare fields directly and invoke Java code that throws an exception.
Or the Java code can do the validation (allowing it to be reused elsewhere).
Learn more: Event Rules