Sunday, 1 January 2023

Coding best practices in D365F&O


There are certain rules developer should follow while developing the solution that helps maintaining a code sanity, optimizing performance and saving a time to fix the CAR report at the very last movement.

Below list would collectively help us do so-

User ‘Firstonly’ keyword while using select statement in X++.

Select only required field list in select query instead of selecting all fields from table.

Use str() functions wherever possible instead of using containers.

Avoid writing a lot of logic on form, instead- a new class should be created and same should be called from form.

Avoid writing all logic in one method (main() or run()), each small functionality should be break down into smaller methods and called as per the requirement, that will be more readable and easy to modify further for new developer.

<<XML documentation>> should be properly written for every method and class written in X++ .

Try to use standard available labels as much as possible.

Try to declare variables as locally as possible.

Never make assignment to ‘this’ variable.

Try to reuse code as much as possible .

Avoid using hard coded text, create and use labels instead.

ttsBegin and ttsCommit must be in same method and at same level of code.

Avoid making ttsBegin/ttsCommit conditional, never add code that requires user interaction within the transaction (ttsBegin and ttsCommit).

New classes for event handlers and delegates need to be named with proper naming.

Wherever possible make use of SUM(), COUNT() functions in ‘while select statement’ as those are more effective.

Use set based transactions wherever possible.

There should not be any dead or unreachable code sections.

Complex blocks of code should be properly commented mentioned the details.

Avoid nested while select and make use of joins of the table.

Check and avoid if any non ending loop exist in code.

Make sure to create table index on creation of new table, basic table properties must be set when new table is created, including – Title field1, title field 2, Primary Index, Label, Table type etc.

Delete action should be added if parent-child tables are included. This would help maintaining a data granularity by removing the orphan records.

Appropriate field groups should be added if table extension crossing 10+ custom fields, all fields more than 10 must be added in new extension.

The table’s FormRef property should be set if applicable.

The Cluster Index property should be filled in if there is only one index on the table.

A static find method should exist for newly created table. This will help reducing unnecessary select statements.

Take get latest before modifying the objects of AOT and at the time of check-in the objects. This will avoid overwriting and impacting other’s development.

Take the get latest of the label file before check-in your modified label file.

Give proper comment while check-in and add the related ADO tasks.

Check the VS mapping if the its mapped to the right branch.

Names of the newly created objects should be indicative to the functionality being created for.

Create all security objects wherever applicable (Privilege, Duties, Roles).

Code clean up – delete unused variables, methods, and classes.

Make sure object names are spelled correctly.

Create EDT/Enums for the multiple use of same data type in the different tables.

CAR report should be generated and fixed.

No comments:

Post a Comment

Filtering Company-Specific Product Templates - SysRecordTmpTemplate lookup

Hi Techies - Recently I have come across a requirement where I needed to display product templates specific to a selected company for a give...