What is the best way to limit the numbers records in a table?

I need to restrict to insert a record into a table if it contains at least 1 record. This table must contain 0 or 1 record at all times. I’m using this table to store a value of one field (It’s a default value which is chosen in the parameters by a user).

I’m trying to do it in validateWrite() method of the table but I’m having trouble distinguishing when the record is inserted and when it’s updated. It must be available to update a record and it must be impossible to insert another record if there is at least 1 record in the table. Deletion can be possible or impossible, not that important.

If the record already has RecId, it’s an update. If RecId is 0, the record is being inserted.

By the way, an alternative design is used by tables implementing the parameter system pattern. In a correctly initialized AX system, they always have exactly one record (per company).

I already tried that, but turns out RecId is zero even when you’re updating it when you check the value in the validateWrite(). I know it doesn’t make too much sense but it does work like this.

I’ll take a look at the mdsn link, thanks.

The article really helped me, thank you.