Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
outlinetrue
stylenone

Basics

The feature allows the Admin to define customized Validation routines on any table. These routines can be executed before Saving or Deleting records on any table. The validation routines can also target specific records in the table the validation is assigned to.

...

This Grid will allow Users to add Custom Validation routines to Save and Delete actions on the application data.

  • Description: A description field to provide an identifying name for this validation routine.

  • Table Name: The Database table name to which this validation is be applied.

  • Table Record: The specific RECID number that should be validated. Leave this blank to apply the validation to all records.

  • Action: Save or Delete options specifying the table action that should be validated.

CAUTION: When creating Custom Validations, it is better to have a handful of large Custom Logic than it is to have numerous amounts of short Custom Logics defined for your Organizations Custom Validations. This is because as the number of Custome Validations that trigger on the same form increases, application performance begins to suffer, and can eventually start risking application timeouts. It is also important to ensure the same Custom Logic is not running multiple times on the same records as this also will reduce application performance if a large number of records undergo this same change at once, such as the case with any Validations that might trigger from a Service Desk Action. The performance issue originates from the delay in starting a new validation after one executes. When this delay occurs multiple times during the execution of an extended task, such as completing a large number of Service Desk Actions, this can push the process to take too long and trigger application timeouts.

...

A User can quickly review the code written for the specific event with the Validate PHPImage Removed image-20240820-165128.pngImage Added button.

Users will be limited to the white-listed functions for PHP in PCR-360. A list of the functions can be seen in PCR-360 by clicking on the HelpImage Removed image-20240820-165145.pngImage Added button.

Include Page
(2024.1) Allowed Functions in Custom Logic
(2024.1) Allowed Functions in Custom Logic

Debug tab

...

The Debug tab shows the results of debug function calls. This debug information is cleared after 24 hours. The Debug tab can be used to monitor data using the Custom Logic.

...

A key/value paired array of User information about the currently logged in User. The example below shows options that are available in this array.

Code Block
languagephp
linenumberstrue
$user = [
     'isSysAdmin' => TRUE
     'isCoordinator' => FALSE
     'isCustomerCenterOnly' => FALSE
     'attributes' => [
		'USERS_RECID' => 494,
		'USERID': "demo",
        'CONTACTS_RECID' => 1
        'NAME' => 'Pcr Demo'
        'FIRST_NAME' => 'Pcr'
        'LAST_NAME' => 'Demo'
        'DEPT_HIERARCHY_RECID' => NULL
        'TENANTS_RECID' => 0
        'EMAIL' => 'demo@pcr.com'
    ]
]

...

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 lookups validations require.

Include Page
(2024.1) Allowed Functions in Custom Logic
(2024.1) Allowed Functions in Custom Logic

Content

There's no easy way to monitor Custom Validation for output, especially while writing the code for it because there's no "real" data to pass through the code when it is being written.

...

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

...

This approach doesn't let you view real data, though. 

  • Not ALL column/value pairs are always included. Some inserts and updates omit columns that have defaults or are left unaltered in a given process.

    • The User writing the validation should monitor the data in order to observe what is being passed through.

Error Messages

Once a Custom Validation has been triggered, regardless of what data input method triggers the Validation, a message will be reported back to the User identifying itself as a result of Custom Validation. The first part of the error will display the name of the organization to help identify that the error was a Custom Validation and not one of the standard errors from the application. The message from the Validation will appear after the name.

...

These two functions setError() and setWarning() can have a number of different returns. In addition to the type of message set, the return will also determine behavior. The following table explains the expected results of using either function and the return values. In the table, "not-false" means any return that is not Boolean false. False-ish values (0, empty string, etc.) do not count.

Function

Return

Result

setError()

false

Error is issued, Save or Delete fails

setError()

not-false

Warning issued, save or delete passes

setWarning()

false

Error is issued, save or deletefails

Note: An additional generic Error line will display because a false return implies an error message should have been set and was not.

  Generic Message text: "A Validation Error has occurred"

setWarning()

not-false

Warning issued, save or delete passes.

setError()

+

setWarning()

false

Error issued with both messages, save or delete fails.

setError()

+

setWarning()

not-false

Warning issued with both messages, save or delete passes.

What this means is that the return dictates whether the action passes (false: no, not-false: yes)and what dialog type Users get (false: error, not-false: warning). Messages just correspond to the type of return sent.

...

 If a Custom Validation is triggered while using a given form, the message will appear in the following manner:

...

Imports

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.

To see the errors, navigate to Admin > Imports/ Exports: Import Files > Imported Records.

...

API

Custom Validations returned from the API will return a status of "failure" and the Customer Validation message.Custom Validation message exampleImage Removed

...


Custom Validations can also be configured to call the API to create other application records.

Sample Validation to API
Code Block
languagexmltitleSample Validation to API
// set the save data
$payload = [
    "type" => "IN",
    "csr" => "1",
    "owner" => "1",
    "owner_type" => "contact",
    "prob_code" => "1",
    "description" => "Sample Validation to create an Incident"
];

$this->call("saveServiceDesk", $payload);

return true;

The above example is for how a User might create a Custom Validation to call the Service Desk API endpoint, and create an Incident. For more information on API functionality see that API Articles in this wiki.


Child pages (Children Display)
styleh6
sorttitle