Virtual Fields Vs Computed Fields


 


Virtual Field:

A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that you can define in a table as if it were a regular data field, but its value is computed on-the-fly based on certain calculations or business logic whenever it is queried. Virtual fields are often used to display derived or computed information without storing it in the database.


Advantages of Virtual Fields:


  • No need to store redundant data in the database.
  • Useful for displaying calculated values without performing calculations every time.

Computed Field:

A computed field in D365FO is similar to a virtual field in that its value is calculated based on certain rules or business logic. However, computed fields are typically defined in the Application Object Tree (AOT) and are often used within forms or reports to display dynamic information based on specific calculations.


Advantages of Computed Fields:

  • Provides dynamic and real-time calculations.
  • Can be used for various display purposes within forms and reports.

In summary, both virtual fields and computed fields are used to display calculated or derived information in Dynamics 365 Finance and Operations. Virtual fields are defined in tables and calculated on-the-fly during queries, while computed fields are often used within forms and reports to display dynamic calculations based on business logic. The choice between them depends on where and how you want to display the calculated information.



Support Faryal's Cusine


Chain of Command VS Event Handlers

 

Differences & Advantages



Chain of Command (COC):

Chain of Command is an extension framework in D365FO that allows developers to customize and extend standard application logic without modifying the original code. It enables you to add new business logic, validations, and modifications to existing methods in base classes. COC works by creating an extension class for the base class you want to modify and then overriding or adding methods within this extension class. COC supports before, after, and around method events.


Advantages of COC:

  • Non-intrusive: Original code remains untouched.
  • Supports method extensions.
  • Facilitates the coexistence of multiple extensions.
Example
class BusinessLogic1 { str doSomething(int arg) { // ... } }


[ExtensionOf(classStr(BusinessLogic1))] final class BusinessLogic1_Extension { str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } }

BusinessLogic1 object = new BusinessLogic1(); info(object.doSomething(33));

Event Handler:

Event handlers are programming constructs that allow you to subscribe to specific events that occur during the execution of application logic. They provide a way to respond to actions or state changes in the system. In D365FO, event handlers are often used to react to events such as record creation, modification, deletion, or specific actions taken by users. Event handlers are decoupled from the base code and are defined in a separate class.


Advantages of Event Handlers:

  • Decoupled: Separates customization from core logic.
  • Supports centralized event management.
  • Allows multiple subscribers to the same event.

In summary, COC and event handlers are both mechanisms to customize and extend Dynamics 365 Finance and Operations without directly modifying the original code. COC focuses on extending methods in base classes, while event handlers focus on reacting to events during application execution. The choice between COC and event handlers depends on the nature of customization required and the specific use case.


Example

class PointWithEvent { // Instance fields. real x; real y; // Constructor to initialize fields x and y. void new(real _x, real _y) { x = _x; y = _y; } void move(real x_offset, real y_offset) { x += x_offset; y += y_offset; this.moved(abs(x_offset) + abs(y_offset)); } delegate void moved(real distance) { } } class PointKeeper { public void createAndMove() { PointWithEvent point = new PointWithEvent(1.0, 2.0); point.moved += eventhandler(this.writeMove); point.move(4.0, 5.0); // Output is "9.0". } public void writeMove(real distance) { info(any2Str(distance)); } }


[PreHandlerFor(classStr(MyClass2), methodstr(MyClass2, publisher))] public static void PreHandler(XppPrePostArgs arguments) { int arg = arguments.getArg("i"); } [PostHandlerFor(classStr(MyClass2), methodstr(MyClass2, publisher))] public static void PostHandler(XppPrePostArgs arguments) { int arg = arguments.getArg("i"); int retvalFromMethod = arguments.getReturnValue(); } public int Publisher(int i) { return 1; }

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...