Best practice for controls on updated properties
The best practices for controls can be summarized in the following bullets:
* If the validity of a property is not linked to the value of another property that can be modified in the same transaction, the control can be done on the control rule of the property.
* If a validity of a property depends on the value of other properties, the control must be done globally at the class level.
The reason for this rule is that you cannot assess in which order the properties have been entered and controlled.
If you want to perform such controls immediately after data entry to enhance the user experience, you can add such code in the UI layer (attached to the representation); however:
For example, if you want to control that no duplicates values exist on a row in a grid, you can write it in the global control code for the main class.
If uni(this.COLLECTION(1..maxtab(this.COLLECTION)).MYKEY)<>0
# A duplicate key exists for the row
ARET= Fmet this.ASETERROR .... # Place here the right error message
End ARET
Endif
The example must be modified as follows:
Local Char KEY(20)(1..)
Local Integer LINES, CURLIN, L_INDEX, I, J
# Let's make a list of the existing codes
For CURLIN=1 to maxtab(this.COLLECTION)
If this.COLLECTION(CURLIN)<>Null and find(this.COLLECTION(CURLIN).ASTALIN,[V]CST_ADEL,[V]CST_ANEWDEL)=0
LINES+=1
KEY(LINES)=this.COLLECTION(CURLIN).MYKEY
L_INDEX(LINES)=CURLIN
Endif
Next CURLIN
# Now we can test the unicity of the codes
J=uni(KEY(1..LINES))
If J<>0
# A duplicate key exists for the row
I=find(KEY(J),KEY(1..J-1))
# L_INDEX(I) is the first duplicate key position, and L_INDEX(J) the second position
ARET= Fmet this.ASETERROR .... # Place here the right error message
End ARET
Endif
Local Char KEY(20)(1..)
Local Integer LINES, CURLIN
# Let's make a list of the existing codes
For CURLIN=1 to maxtab(this.APARENT.COLLECTION)
If this.APARENT.COLLECTION(CURLIN)<>Null and find(this.APARENT.COLLECTION(CURLIN).ASTALIN,[V]CST_ADEL,[V]CST_ANEWDEL)=0
LINES+=1
KEY(LINES)=this.APARENT.COLLECTION(CURLIN).MYKEY
Endif
Next CURLIN
If uni(KEY(1..LINES))<>0
# A duplicate key exists for the row
ARET= Fmet this.ASETERROR .... # Place here the right error message
End ARET
Endif