Business
Central 29 adds IsDirty to the Record API. It lets your AL code ask a record
whether anything has changed since it was loaded, so you can skip writes that
aren't needed and stop tracking change state by hand. In this post I'll show
how it behaves on a Customer Card, and where it fits in real code.
What
IsDirty does
Record.IsDirty()
tells you whether a record instance has changed since it was loaded. It returns
true when the in-memory values differ from what came back from the database,
and false when they still match.
procedure
IsDirty(): Boolean
That gives
you a clean way to decide whether a record needs validating, saving, or a
prompt to the user, without keeping track of the state yourself.
If you've
worked with RecordRef, this will look familiar. RecordRef.IsDirty() has been
around since runtime 5.0. Version 29 brings the same capability to the Record
data type, so you ask the question directly on the record you're already
working with.
Seeing it
on a Customer Card
The quickest
way to see what IsDirty reports is a page action. Add this page extension to a
sandbox, open any customer, and run the action.
pageextension
50100 "Customer Card IsDirty Demo" extends "Customer Card"
{
actions
{
addlast(Processing)
{
action(IsDirtyDemo)
{
ApplicationArea = All;
Caption = 'IsDirty Demo';
ToolTip = 'Shows how
Record.IsDirty reports changes on this customer.';
trigger OnAction()
var
Customer: Record Customer;
DirtyMsg: Label 'IsDirty
after %1: %2', Comment = '%1 = step name, %2 = Yes or No';
begin
Customer.Get(Rec."No.");
Message(DirtyMsg, 'Get',
Customer.IsDirty());
Customer.Name := 'IsDirty
test';
Message(DirtyMsg, 'changing
Name in memory', Customer.IsDirty());
end;
}
}
}
}
Set runtime
to 18.0 or later in app.json before you build it.
The first
message shows No. The record has just been loaded and nothing has changed.
The second
message shows Yes. The Name in memory no longer matches what's stored in the
database.
Version
and availability
IsDirty
ships with Business Central 2026 release wave 2, version 29.
The runtime
floor is 18.0. Compiling against runtime 17.0 produces diagnostic AL0666,
stating that IsDirty is not available in that runtime version and that 18.0 or
greater is required. Set runtime to 18.0 in app.json before you use it.
No comments:
Post a Comment