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 rowARET= Fmet this.ASETERROR .... # Place here the right error messageEnd ARETEndif
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 codesFor CURLIN=1 to maxtab(this.COLLECTION)If this.COLLECTION(CURLIN)<>Null and find(this.COLLECTION(CURLIN).ASTALIN,[V]CST_ADEL,[V]CST_ANEWDEL)=0LINES+=1KEY(LINES)=this.COLLECTION(CURLIN).MYKEYL_INDEX(LINES)=CURLINEndifNext CURLIN# Now we can test the unicity of the codesJ=uni(KEY(1..LINES))If J<>0# A duplicate key exists for the rowI=find(KEY(J),KEY(1..J-1))# L_INDEX(I) is the first duplicate key position, and L_INDEX(J) the second positionARET= Fmet this.ASETERROR .... # Place here the right error messageEnd ARETEndif
Local Char KEY(20)(1..)Local Integer LINES, CURLIN# Let's make a list of the existing codesFor 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)=0LINES+=1KEY(LINES)=this.APARENT.COLLECTION(CURLIN).MYKEYEndifNext CURLINIf uni(KEY(1..LINES))<>0# A duplicate key exists for the rowARET= Fmet this.ASETERROR .... # Place here the right error messageEnd ARETEndif