CLEAR vs INIT functions in Business Central

DoufuDoufu
1 min read

What is the difference between CLEAR and INIT functions? Clear(Record) vs Record.Init()

CLEAR function

When used on a variable, i.e. Clear(SomeVariable), it simply clears the value that is stored to its default state. For example, if it is a number variable, it will be set to 0 (zero), a date variable to an undefined date (0D) and so on. Clear can be used on a Guid data type, and in this case sets the GUID to all zeroes.

When used on a record, i.e. Clear(Rec), or an array, all elements are cleared. It resets all the filters, resets the primary key and all fields will be initialized based on the InitValue property. If ChangeCompany is used, it will reset back to the original company.

INIT function

Used for initializing a new record in a table for insertion. It will assign default values to all the fields in the record, including the SystemId field.

Both of these functions might seem to be doing the same thing, setting fields to their default state, but they are used under different circumstances for different purposes.

0
Subscribe to my newsletter

Read articles from Doufu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Doufu
Doufu

Current project developments on Microsoft platforms such as Business Central, Dynamics 365 Sales, Power Platform and occasionally Python. Used to get my paws dirty on Android and Web development.