The implementation
The Singleton Pattern is an Architectural Pattern, which means we need to create at least one table and a page. The Pattern tells us how to structure these:
Let's create a new table, and define the primary key as in the diagram. We have to save the table, and name it as Example Setup
with an ID of 50000
, as shown:
We also need to define a Page where the users can edit the setup. We have to prevent users from accidentally deleting the setup or creating additional records in the table.
The Page contains a small C/AL code snippet that creates a record in the setup table, just in case the record does not exist:
We also change the InsertAllowed and DeleteAllowed properties to No
.
Although we have already made sure that a record always exists in the OnOpenPage
trigger, it is also recommended to create the record in the Company-Initialize Codeunit. This Codeunit gets called each time we create a new company, or when upgrading to a new version.
In fact, the only...