Clear Vs INIT?

I know the difference between both fucntion. But in one of the Navision course that I visited they informed us to always use INIT + Set PrimaryKEy to 0 (PK := 0) instead of using clear. They explain this to us but unfortunately i forgot why.

Now my question is: is this true that we should always use INIT + PF := 0 to INIT a REC? and we should not use Clear?

Can anyone explain why?

Ps: I am using NAv_2016

I’ve never heard that before. Although it’s been sometime since I’ve taken a class. I’d be interested in hearing the why. I feel both commands continue to have their uses. it depends on the situation.

INIT (alone) - This will reset all fields (except those in the primary key) to their default values. This command is ok if you code will handle assigning primary key values to avoid conflicts.

INIT + blank primary key fields - Use this if you also need to clear primary key values. An example might be when your primary key contains auto-increment fields. A CLEAR will accomplish the same thing.

CLEAR - Provides the additional step of clearing any global variables.

Hi Babrown,

First thanks for your reply, one of the most important feature in any table is the “Init Value” property for the field. for each field we can define the Init value once we use the INIT function. So I would says that’s why the informed us to always use INIT + Blank Primary Key.
“Clear” would for example set my Decimal field to ‘0’! and this may not be a good idea if I already defined that the initial value of this field should be 1.

So that Why I would say -----> INIT + Blank Primary KEY is better :slight_smile:

I should have added that if you use CLEAR, then start the new record with an INIT. It’s not a case of 1 is better than the other. You have to consider the situation.

INIT will not clear global variables.

CLEAR blanks out the primary key fields without the extra code.

Interesting thread.

Personally I have always had some bad wipes when it comes to using CLEAR. So I am always trying to avoid using it.

Except to clear DateTimes, automations and guids.

For records, then unless I had a needed it to also clear the filters (extra work), then I’m always using INIT (+ blank primary fields).

The main difference is to what I can see, if you don’t care about the filters, that clear doesn’t initiate it. It doesn’t apply the Init values to the record, as INIT does.

But that doesn’t really matter, as the first time you assign a value to the record, then NAV will automatically init the values of the remaining fields.

So either ways really works the same, when it comes to practical usage.