Customization Sample Code
The code in this section uses the example of a fictional tax ID validation for the Czech Republic, implemented using non-intrusive customization. In this example, the tax ID cannot be less than two characters.
The icValueToValidate parameter supplies the code, number, or ID to be validated. The icTableName and icFieldName parameters can be used to distinguish between the records to be validated, that is, business relation tax details, supplier tax details, or customer tax details. The icFieldName parameter can be used to distinguish between different types of tax ID for the same country, for example, federal or state tax IDs.
/* Customization code for component BFormatSet */
&scoped-define class-version 0.0
{ definition/bformatset.i }
/*
Procedure: ValidateFormatTaxId
Description:
This method can be used for validation of correct format of the Tax ID.
- instance less method
Parameters:
input icValueToValidate
(Code/Number/ID to be validated)
input icTableName
()
input icFieldName
()
input icCountryCode
()
input icStateCode
()
input icAddressType
(Address type.)
input icErrorType
(Type of error if the format does not comply with the format. (Error/Warning).)
output oiReturnStatus
(Return status of the method.)
*/
PROCEDURE BFormatSet.ValidateFormatTaxId.after:
define variable viLocalReturn as integer init 0.
define variable viDummy as integer.
assign t_parameter.oiReturnStatus = -98.
MAIN_BLOCK:
do on error undo, leave:
/* CZECH TAX ID VALIDATION */
if t_parameter.icCountryCode = "CZE" and
t_parameter.icAddressType = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
then do:
/* If not entered - is OK */
if t_parameter.icValueToValidate = '':U or
t_parameter.icValueToValidate = ?
then leave MAIN_BLOCK.
/* First two letters have to be CZ – so length cannot be less than 2 characters */
if length(t_parameter.icValueToValidate, "CHARACTER") < 2
then do:
run SetMessage (
input 'Czech Tax ID cannot be shorter than 2 characters.',
/* icMessage */
input '':U, /* icArguments */
input t_parameter.icTableName + '.':U + t_parameter.icFieldName,
/* icFieldName */
input t_parameter.icValueToValidate, /* icFieldValue */
input t_parameter.icErrorType, /* icType */
input 3, /* iiSeverity */
input '':U, /* icRowid */
input 'CUSTOM-001':U, /* icFcMsgNumber */
input '':U, /* icFcExplanation */
input '':U, /* icFcIdentification */
input '':U, /* icFcContext */
output viDummy).
assign viLocalReturn = (if t_parameter.icErrorType = 'E':U then -1 else 1).
leave MAIN_BLOCK.
end.
/* Other validations ………… */
end. /* if t_parameter.icCountryCode = "CZE" and */
end. /* MAIN_BLOCK */
assign t_parameter.oiReturnStatus = viLocalReturn.
END PROCEDURE.