✏️ Explanatory Question

What are display and edit methods in Dynamics 365 Finance & Operations? How do they differ, why must you avoid CRUD operations inside them, and how do you cache a display method on a grid for performance?

👁 2 Views
📘 Detailed Answer
🟢 Easy
No previous question
No next question
💡

Answer with Explanation

D365 F&O • X++ INTERVIEW

Display & Edit Methods in Dynamics 365 Finance & Operations

Question 18 — Deriving values for the UI, caching them on grids, and why they must stay lightweight.

Interview Question

What are display and edit methods in Dynamics 365 Finance & Operations? How do they differ, why must you avoid CRUD operations inside them, and how do you cache a display method on a grid for performance?

Model Answer (Short)

A display method returns a read-only value that is calculated at runtime and shown on a form or report — the user cannot edit it. An edit method is similar but read-write: it both displays a value and accepts user input, receiving a set parameter to write the entered value back. Both are declared with the display / edit modifier and run once per visible row, so they must be lightweight — you should never perform CRUD (insert/update/delete) or heavy queries inside them. On grids, display methods should be cached (via cacheAddMethod or the CacheDataMethod property) so they aren't re-evaluated on every repaint.

Display vs. Edit Methods

Key characteristics

  • Display method — read-only; returns a value to show. Runs for every visible record.
  • Edit method — read-write; shows a value and lets the user change it, using a set boolean and a value parameter.
  • Both can live on a table (reusable across forms) or directly on a form data source / form.
  • They are evaluated on the UI thread per row, so performance matters a lot.
GOLDEN RULE
Display = read-only  •  Edit = read-write  •  No CRUD inside either

Why avoid CRUD & heavy logic

  • They run once per row and on every repaint, so database writes would fire repeatedly and unpredictably.
  • Writing data during a display/refresh can cause data integrity issues and locking.
  • Expensive queries slow down form load and scrolling noticeably.
  • Keep them to simple lookups, formatting, or cached values only.

Caching display methods on grids

  • Use cacheAddMethod() on the form data source's init to cache a display method's result.
  • Alternatively set the CacheDataMethod property to Yes on the control.
  • Caching means the method is evaluated once per record and reused, not re-run on each repaint.
  • Call dataSource.cacheCalculateMethod() when you need to force a refresh of a cached value.

Prerequisites (Rule 5)

  • Visual Studio with the Dynamics 365 developer tools.
  • A custom model / package for your objects.
  • A table or form data source on which to declare the method.
  • A form/grid where the method is bound to a control.

Code Example — Display method on a table

// On the table (reusable on any form)
public display Amount displayTotalAmount()
{
    // Lightweight: simple arithmetic on already-loaded fields
    return this.Qty * this.Price;
}

Edit method (read-write)

public edit Description editRemarks(boolean _set, Description _remarks)
{
    Description ret = this.Remarks;

    if (_set)
    {
        // User typed a value -> store it in the buffer (no DB write here)
        this.Remarks = _remarks;
        ret = _remarks;
    }

    return ret;
}

Caching a display method on the form data source

// In the form data source init() method
public void init()
{
    super();

    // Cache the table display method so it runs once per record
    this.cacheAddMethod(tableMethodStr(AbcOrderLine, displayTotalAmount));
}

Display vs. Edit Method

Aspect Display Method Edit Method
Editable by user No (read-only) Yes (read-write)
Signature Returns a value Takes boolean _set + value, returns value
Typical use Show a derived/looked-up value Show and capture an unbound value
Caching Recommended on grids Not typically cached
CRUD allowed inside No No

Points the interviewer wants to hear

  • Display = read-only; edit = read-write with a set flag.
  • Both run per visible row, so keep them lightweight.
  • Never perform CRUD or heavy queries inside them.
  • Cache grid display methods with cacheAddMethod / CacheDataMethod.
  • Prefer declaring reusable methods on the table rather than the form.

Likely Follow-up Questions

  • Why do display methods hurt performance on large grids if not cached?
  • What is the purpose of the _set parameter in an edit method?
  • How do you force a cached display method to recalculate?
  • Should a display method be defined on the table or the form? Why?

Key Takeaway

Display methods show read-only derived values and edit methods also capture input, but both execute per row — so keep them lightweight, never do CRUD inside them, and cache display methods on grids for smooth performance.

No previous question
No next question