project BLF > class Database Component > method ValidateCustomFields
Description
Check if values on active custom fields meet the validation criteria in the definition of the custom field and return an error if they don't.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/database.p)
<M-4 run DataDescription
(input '' (icRowids),
input '' (icPkey),
input '' (icObjectIds),
input true (ilAllTables),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<Q-20 run GetCustomFieldsForTable (all) (Read) (NoCache)
(input '', (TableName)
input vcFcComponentName, (ComponentName)
output dataset tqCustomFieldsForTable) in BCustomField >
for each tqCustomFieldsForTable on error undo, throw:
assign vcFieldName = if num-entries(tqCustomFieldsForTable.tcCustomFieldFieldName, ":") = 2
then entry(2, tqCustomFieldsForTable.tcCustomFieldFieldName, ":")
else tqCustomFieldsForTable.tcCustomFieldFieldName.
if tqCustomFieldsForTable.tcCustomFieldUIControlType = "ComboBox"
then do:
if tqCustomFieldsForTable.tiStoredSearch_ID = 0 or
tqCustomFieldsForTable.tiStoredSearch_ID = ?
then do:
<Q-22 assign vlFcQueryRecordsAvailable = CustomFieldValues (NoCache)
(input tqCustomFieldsForTable.tcCustomFieldFieldName, (BusinessFieldName)
input ?, (Value)) in BCustomField >
assign vlCustomList = vlFcQueryRecordsAvailable <> no.
end.
else assign vlCustomList = yes.
end.
else assign vlCustomList = no.
assign vcTable = substr(entry(1, vcFieldName, "."), 2, -1, "CHARACTER").
find first tFcDynRel where
tFcDynRel.tcFcTo = vcTable
no-error.
if available tFcDynRel
then do:
assign vhField = tFcDynRel.thFcSBuffer:buffer-field(entry(2, vcFieldName, ".")).
create query vhQuery in widget-pool "non-persistent".
vhQuery:forward-only = yes.
vhQuery:set-buffers(tFcDynRel.thFcSBuffer).
vhQuery:query-prepare("for each t_s" + tFcDynRel.tcFcTo + " where" +
" t_s" + tFcDynRel.tcFcTo + ".tc_Status = 'N' or" +
" t_s" + tFcDynRel.tcFcTo + ".tc_Status = 'C'").
vhQuery:query-open().
vhQuery:get-first().
do while not vhQuery:query-off-end:
/* Check mandatory */
if tqCustomFieldsForTable.tlCustomFieldIsMandatory and
(vhField:buffer-value = ? or
(tqCustomFieldsForTable.tcCustomFieldDataType = "c" and
vhField:buffer-value = ""))
then do:
<M-7 run SetMessage
(input trim(#T-18'You must enter this field.':255(9436)T-18#) (icMessage),
input '' (icArguments),
input vcFieldName (icFieldName),
input vhField:buffer-value (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
input 'BLF-327' (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
assign oiReturnStatus = -1.
end.
/* Check format */
if tqCustomFieldsForTable.tcCustomFieldDataType = "c" and
tqCustomFieldsForTable.tiCustomFieldDisplayLength > 0 and
length(vhField:buffer-value, "CHARACTER") > tqCustomFieldsForTable.tiCustomFieldDisplayLength
then do:
<M-8 run SetMessage
(input trim(#T-19'Value is too long.':255(9437)T-19#) (icMessage),
input '' (icArguments),
input vcFieldName (icFieldName),
input vhField:buffer-value (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
input 'BLF-328' (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
assign oiReturnStatus = -1.
end.
if tqCustomFieldsForTable.tcCustomFieldDataType = "i" and
tqCustomFieldsForTable.tiCustomFieldDisplayLength > 0
then do:
assign viValue = vhField:buffer-value
viMaxValue = 1.
do viFcCount1 = 1 to tqCustomFieldsForTable.tiCustomFieldDisplayLength:
assign viMaxValue = viMaxValue * 10.
end.
if viValue >= viMaxValue or
viValue <= - viMaxValue
then do:
<M-9 run SetMessage
(input trim(#T-15'Value is too large.':255(472)t-15#) (icMessage),
input '' (icArguments),
input vcFieldName (icFieldName),
input string (vhField:buffer-value) (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
input 'BLF-329' (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
assign oiReturnStatus = -1.
end.
end.
if tqCustomFieldsForTable.tcCustomFieldDataType = "d" and
tqCustomFieldsForTable.tiCustomFieldDisplayLength > 0
then do:
assign vdValue = vhField:buffer-value
vdMaxValue = 1.
do viFcCount1 = 1 to tqCustomFieldsForTable.tiCustomFieldDisplayLength - tqCustomFieldsForTable.tiCustomFieldPrecision:
assign vdMaxValue = vdMaxValue * 10.
end.
if vdValue >= vdMaxValue or
vdValue <= - vdMaxValue
then do:
assign vcDisplayValue = <M-11 DisplayDecimal
(input vdValue (idDecimal),
input '' (icFormat)) in database>.
<M-10 run SetMessage
(input trim(#T-16'Value is too large.':255(472)t-16#) (icMessage),
input '' (icArguments),
input vcFieldName (icFieldName),
input vcDisplayValue (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
input 'BLF-330' (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
assign oiReturnStatus = -1.
end.
/* Round excess decimals (no error message) */
assign vhField:buffer-value = round(vdValue, tqCustomFieldsForTable.tiCustomFieldPrecision).
end.
/* Check custom value list */
if vlCustomList and
vhField:buffer-value <> "" and
vhField:buffer-value <> ?
then do:
if tqCustomFieldsForTable.tiStoredSearch_ID = 0 or
tqCustomFieldsForTable.tiStoredSearch_ID = ?
then do:
<Q-1 assign vlFcQueryRecordsAvailable = CustomFieldValues (NoCache)
(input tqCustomFieldsForTable.tcCustomFieldFieldName, (BusinessFieldName)
input vhField:buffer-value, (Value)) in BCustomField >
if vlFcQueryRecordsAvailable = no
then do:
<M-2 run SetMessage
(input trim(#T-22'Invalid value.':100(473)T-22#) (icMessage),
input '' (icArguments),
input vcFieldName (icFieldName),
input vhField:buffer-value (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
input 'BLF-326' (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in database>
assign oiReturnStatus = -1.
end.
end.
else do:
<Q-40 run StoredSearchPrim (all) (Read) (NoCache)
(input tqCustomFieldsForTable.tiStoredSearch_ID, (StoredSearchID)
input ?, (Name)
input ?, (LookupReference)
input ?, (UsrId)
input ?, (CompanyId)
output dataset tqStoredSearchPrim) in BStoredSearch >
find tqStoredSearchPrim where
tqStoredSearchPrim.tiStoredSearch_ID = tqCustomFieldsForTable.tiStoredSearch_ID
no-error.
if available tqStoredSearchPrim
then do:
<M-79 run ValidateCustomFieldsGenCode
(input tqStoredSearchPrim.tcStoredSearchLookupRef (icGenCode),
input vcFieldName (icFieldName),
input vhField:buffer-value (icFieldValue),
input tFcDynRel.thFcSBuffer::tc_Rowid (icRowid),
output viFcReturnSuper (oiReturnStatus)) in database>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
end.
vhQuery:get-next().
end.
vhQuery:query-close().
delete object vhQuery.
assign vhQuery = ?.
end.
end.
finally:
if vhQuery <> ?
then delete object vhQuery.
end finally.