Dynamics 365 Business Central: How to set the initial value (Automatically set default value for field)

Dynamics 365 Business Central

Hi, Readers.
Yesterday someone asked me how to set the checkbox to true by default in Business Central when adding a new record. So, in this post, I would like to discuss how to set the initial value in BC. Hope this will help.

In fact, this is not very difficult, there are two ways to do this.

1. Using the InitValue property on the table field.

InitValue property: Sets the initial value of this field when a user creates a new record.

Applies to: Table Field

Remarks: This attribute is only important if you create the record in a window or by using the AL methods Clear Method, or ClearAll Method. For example, this attribute is commonly used in Boolean fields when you want either true or false to be the default.

For example: Add a new field in customer table and set the InitValue property.

Display it on the customer card page.

Test Video:

Note: InitValue property cannot be modified via TableExtension. So, we can’t modify the initial value of the standard field with this way.

The property ‘InitValue’ cannot be customized.AL(AL0246)

If we need to modify the initial value of a standard field, how do we do it? Let’s look at the second way.

2. Adding code in one or more of the following triggers (or even better in an event subscriber to these triggers):
OnInsert Trigger (Table)
OnBeforeInsert Trigger (TableExtension)
OnAfterInsert Trigger (TableExtension)
OnNewRecord Trigger (Page)
OnInsertRecord Trigger (Page)

For example:
OnInsert Trigger (Table): Runs when a user inserts a new record into the table.

OnBeforeInsert Trigger (TableExtension): Runs when a user inserts a new record into the table.

OnAfterInsert Trigger (TableExtension): Runs when a user inserts a new record into the table.

Test Video:

OnNewRecord Trigger (Page): Runs after a new record is initialized, but before it is inserted as a record in the table.

OnInsertRecord Trigger (Page): Runs before a new record is inserted into the table.

Test Video:

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL