Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Scroll Health Check: The link has been rewritten to its master page by check 'P16'.

...

Custom Validation shares a set of common syntax and available functions with the other types of Custom Logic. There are also various built in functions to assist in querying data in order to do the look ups validations require.

...

If only the key names of the $data array are of interest, that is always the database row that is being validated. The The columns that belong to the table can be found in the Data Dictionary: by navigating to "Admin > Data Dictionary"

Look up the table that the code is being written for, the column names are the keys that are expected to be seen in that variable, this will enable references to them to be made in the code. For example, SERVICES:

...

  1. Custom Validation - see the code being written
    • Navigate to "Admin > Custom Logic > Validation" to view the records.
  2. Form the Validation runs against (example from above, Service Form)
  3. In the Custom Validation code, add this to the top:

    Code Block
    languagephp
    linenumberstrue
    $dataMap = [];
    // Covers undefined variable bug - $data IS defined during execution
    if (!isset($data)) {
    $data = [];
    }
    foreach ($data as $column => $item) {
    // Replace strings for values that don't convert well
    // switch isn't naturally type-strict, so the cases need to be.
    switch (true) {
    case $item === null:
    $item = 'null';
    break;
    case $item === true:
    $item = 'true';
    break;
    case $item === false:
    $item = 'false';
    break;
    case $item === '':
    $item = '{empty string}';
    break;
    }
    $dataMap[] = $column . ' => ' . $item;
    }
    $this->setError(implode("<br>", $dataMap));
    return false;


  4. Once that's added to the CV code, go to the Form where the CV is applied. Save the record.

...

When a Custom Validation is triggered during an Import the message will be output into the Imported Records grid as an Error. The message content from the Error will appear in the 'Error Description' column of the grid.

...