Tables fields
Ids
Primary key should have only 1 digit (1,2,3, etc.) Other identifications should use houndreads and every group should have their own houndreads Data should use thousands.
GetByXYZ
Usually, for other identifications we prepare a function GetByXYZ(X, Y, Z): boolean. It should work similar as GET(PK).
Line No.
If the primary key contains field Line No. Pimics shouldn't save 0 into this field. It means we need to take care in OnInsert trigger and preapre a function GetLastLineNo to use it outside of the table. Line No. should increase by 10000.
Examples:
- table 70114111 "PIMX Allocation Line"
- procedure GetLastLineNo(_Type: Option; _Code: Code[20]; _AllocationType: Option): Integer;
- procedure GetLastLineNo(): Integer;
Relations in tables
If there is a relation between two tables and this relation needs to fill up more fields, the table that holds the relation data should have a function InitFromXXX(XXX: Record XXX), where XXX is the table.
1 function in 1 codeunit
1 bigger funcion should be in 1 codeunit, so we will be able to use it from different places and from test. We have enough object to create. Each codeunit sohuld contain enough events to make a customization.
Examples:
- codeunit 70113762 "PIMX Publication Reorganize"
- codeunit 70113741 "PIMX Edit HTML"
UI codeunits
If it is not possible to call codeunit directly from page (See 1 function in 1 codeunit). We should create a function in an UI codeunit and use the same function from List and Page or other places. UI codeunit is usually per module or section.
Examples:
- codeunit 70113773 "PIMX Master Data UI Library"
- codeunit 70113794 "PIMX Database UI Library"
Object-Oriented Design
Please thing Object Oreinted. It means instead of adding new parameter to a function maybe it is better to add SetXXX, GetXXX or ParamXXX function to set the parameter especaility in 1 function in 1 codeunit.
Accesibility
The most procedures should be created as internal/local or eventl. codeunit should have Access = Internal.
No code on pages
Pages shouldn't contain any code to make changes in database. Only code to update user interface can be on page. Pages should use 1 line call in Actions, everything needs to be written in Function Codeunit, UI Codeunit, or if it is specific function for the page create a new page management codeunit.
Examples:
- codeunit 4006595 "PIMX Import Wizard Management" and page 4006608 "PIMX Excel Import Wizard"
- codeunit 70113774 "PIMX Drop Documents" and page 70113907 "PIMX Drop Cat Doc. FactBox"
Static, Single instance and Helper codeunits
C# has static classess, it is basically codeunit with procedure where there is no interaction with other procedures. It means there is no global variables. We can have also this kind of codeunits in Pimics in that case set it as Single Instance, because it is faster to initizalize the codeunit and it will be easier to identify this kind of the codeunits. We should also include Helper in the name of CU.
Examples:
- codeunit 70113813 "PIMX Text Helper"
- codeunit 70113776 "PIMX Xml"
- codeunit 70113752 "PIMX Options Conversions"