Documents > BPS V2 Script API
bps::FieldValidator Class Reference

This class implements the BPS table field validator. More...

Public Types

enum  Status {
  StatusOK = 0,
  StatusMissing = 1,
  StatusInvalid = 2,
  StatusDuplicate = 3,
  StatusBadRef = 4
}
 Return status from check function. More...

Public Member Functions

Boolean checkDelete (Object aRecord)
 Checks if the record data is valid for delete.
Boolean checkInsert (Object aRecord)
 Checks if the record data is valid for insert.
Boolean checkUpdate (Object aRecord)
 Checks if the record data is valid for update.
 FieldValidator (Datastore aDatastore, String aTable)
String message (Status aStatus)
 Get standard message for a status.

Properties

String lastColumn
 Column on which the the last error occurred.
Status lastStatus
 The status set by the recent called check method.

Detailed Description

This class implements the BPS table field validator.

The validator must be registered in the central system settings: In folder Validators there must be a key/value pair where the key is the table name, and the value the path to the validation script.

Check out the standard validators in directory [bpsdir]/scripts/validators as reference how to implement a validator.

Example usage:

var ds = new bps.Datastore();
with (ds) {
connection = 'pgprod';
username = 'prod';
password = 'prod1234';
if (!loadConnection())
throw Error("Invalid connection.\nKnown connections are: "+bps.Datastore.connections);
connect();
purgeActors();
checkin();
}
var rec = { c_key: 100, c_code: 'CH', c_name: 'Switzerland' };
var fv = new bps.FieldValidator(ds,'t_countries');
print(fv.checkUpdate(rec));
print(fv.lastStatus);
print(fv.lastColumn);
ds.checkout();
ds.disconnect();

Member Enumeration Documentation

Return status from check function.

Enumerator:
StatusOK 

All checks passed ok.

StatusMissing 

Mandatory field, but no value (null/empty).

StatusInvalid 

The input is invalid (too short, too long, wrong data).

StatusDuplicate 

Unique field, but same value found in other record.

StatusBadRef 

Key not found in referenced relation table.

Constructor & Destructor Documentation

bps::FieldValidator::FieldValidator ( Datastore  aDatastore,
String  aTable 
)
Parameters
aDatastoreThe datastore connection to use.
aTableThe name of the table to validate for.

Member Function Documentation

Boolean bps::FieldValidator::checkDelete ( Object  aRecord)

Checks if the record data is valid for delete.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.
Boolean bps::FieldValidator::checkInsert ( Object  aRecord)

Checks if the record data is valid for insert.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.
Boolean bps::FieldValidator::checkUpdate ( Object  aRecord)

Checks if the record data is valid for update.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.
String bps::FieldValidator::message ( Status  aStatus)

Get standard message for a status.

Parameters
aStatusThe status to get the message for.
Returns
Standard message for failure status. For StatusOK an empty string is returned.

Property Documentation

String bps::FieldValidator::lastColumn
read

Column on which the the last error occurred.

Empty in case last check passed.

Status bps::FieldValidator::lastStatus
read

The status set by the recent called check method.