Mastering Precision: Coding Standards in Microsoft Dynamics 365 for Finance and Operations :: Latest 2024

 

Microsoft Dynamics 365 F&O Coding Standards: A Comprehensive Guide

Introduction

This blog serves as a guide for developers working on Microsoft Dynamics 365 for Finance and Operations, outlining essential coding standards, development requirements, and guidelines for efficient code development.

Development Requirements

Models and Packages

  • Model Definition

    • A model is a group of elements constituting a distributable software solution.
    • Models belong to a package.
  • Package Definition

    • A package is a deployment and compilation unit of one or more models.
    • It includes model metadata, binaries, and associated resources.

Model Creation Best Practices

  • Always create a new model for development purposes.
  • Use the 'CUS' layer.
  • Notify all developers when creating a new model.
LayerDescription
USRThe user layer is for user modifications, such as reports.
CUSThe customer layer is for modifications that are specific to a company.
VARValue Added Resellers (VAR) can make modifications or new developments to the VAR layer as specified by customers or as a strategy for creating an industry-specific solution.
ISVWhen an Independent Software Vendor (ISV) creates their own solution, their modifications are saved in the ISV layer.
SLNThe solution layer is used by distributors to implement vertical partner solutions.
FPKThe FPK layer is an application object patch layer reserved by Microsoft for future patching or other updates. (Refer to Patch Layers for more information.)
GLSWhen the application is modified to match country or region-specific legal demands, these modifications are saved in the GLS layer. (Note: Consolidated into the SYS layer in Microsoft Dynamics AX 2012 R3.)
SYSThe standard application is implemented at the lowest level, the SYS layer. The application objects in the standard application can never be deleted.

Development Topology

  • Different projects may have distinct development topologies.
  • Ensure you are working on the correct development topology.
  • Consider local development environments and cloud-hosted environments.

Project Naming Conventions

  • Refer new projects to custom models created for development.
  • Use a unique ticket number (UT) or a meaningful description for project names.

Development Guidelines

Object Naming Conventions

  • Object extensions should be named as xxxx.ExtensionSXA.
  • New classes for event handlers and delegates should be named as SXAxxx_EventHandler.
  • Follow proper naming conventions for classes and tables.

Coding Best Practices

  • Avoid 'hard coded' values/labels; retrieve values from the database.
  • Create a new label file in the custom model for multiple languages.
  • Use customization-specific extensions.
  • Add comments with the Unique Ticket number/task description for all modifications.
  • Keep source code backups before modifying existing objects.

Capitalization Styles

  • Follow camel case, pascal case, upper case, or lower case conventions as needed.

Commenting Changes in the Code

  • Comment all changes in the code for better traceability.
  • Utilize Codes 'Sn' & 'En' for commenting new or replaced code.
  • Use Codes 'So' & 'Eo' for commenting out multiple rows of code.
  • Codes 'N' & 'O' are used for commenting new methods or one line of code, respectively.

SQL Statements

  • Apply rules for efficient SELECT statements, including the use of SUM(), COUNT(), UPDATE_RECORDSET, and DELETE_FROM.
  • Comment on the SELECT statement to indicate the intended index.

Do's and Don'ts

  • Include try-catch around transactions that could result in deadlock.
  • Run code on AOS whenever possible.
  • Keep database transactions short.
  • Use throw instead of ttsAbort.
  • Avoid autoDeclaration of form controls; access data source fields.

Developer Testing

  • Ensure sufficient unit testing in the Development Environment.
  • Aim for 100% code coverage in tests.
  • Understand how the application is used from a user's point of view for effective testing.

Code Review Checklist

  • Check adherence to coding standards, naming conventions, X++ best practices, error handling, performance, and optimization.
  • Review documentation completeness.

Additional Best Practices

Exception Handling

Always handle exceptions gracefully by providing meaningful error messages and logging. Avoid using exceptions for regular program flow control.

  • Example: Instead of relying on exceptions for basic validation, use conditional statements and log the relevant information.

Index Usage

When writing select statements, leverage appropriate indexes to optimize database queries. Ensure that the WHERE clause aligns with the index structure for efficient data retrieval.

  • Example: If querying sales data by order date, use an index on the order date field to improve query performance.

Code Reusability

Encourage code reusability by creating functions and methods that can be easily integrated into different parts of the application.

  • Example: If you have a set of utility functions for data validation, reuse them across multiple modules in your project.

Regular Code Reviews

Conduct regular code reviews within your development team to identify potential issues, enforce coding standards, and share knowledge among team members.

  • Example: Schedule weekly code review sessions to ensure code quality and consistency across the project.

Documentation Standards

Maintain clear and comprehensive documentation for your code, including inline comments, method headers, and high-level project documentation. This helps developers understand the purpose and functionality of each component.

  • Example: Use consistent documentation templates for method headers, specifying parameters, return values, and any exceptional cases.

Version Control

Utilize version control systems, such as Azure DevOps or Git, to track changes, collaborate effectively, and revert to previous states if needed.

  • Example: Before starting any significant development, create a new branch in your version control system to isolate changes until they are ready for integration.

Performance Testing

Incorporate performance testing into your development process to identify and address potential bottlenecks early in the development lifecycle.

  • Example: Simulate scenarios where a high volume of transactions is processed simultaneously to assess the system's scalability.

Security Considerations

Adhere to security best practices when handling sensitive data. Implement proper access controls, encryption, and other security measures.

  • Example: Encrypt user credentials when storing them in the database to protect sensitive information.

By incorporating these additional best practices into your D365 F&O development workflow, you can enhance code quality, maintainability, and the overall success of your projects. Always stay updated on the latest platform features and improvements to continually optimize your development practices. Happy coding!

Conclusion

By following these coding standards and best practices, developers can contribute to the quality and efficiency of project delivery in Microsoft Dynamics 365 for Finance and Operations.

Comments

Popular posts from this blog

How to Export and Import an Agent in Microsoft Copilot Studio

Supply Chain Optimization in Dynamics 365 F&O: Inventory Management and Procurement Strategies

Tax Management and Compliance in D365 F&O: VAT, Sales Tax, and Regulatory Reporting