INSERT Function (Record)
Inserts a record into a C/SIDE table.
[Ok :=] Record.INSERT([RunTrigger])
Parameters
- Record
-
Type: Record
The record that you want to insert.
- RunTrigger
-
Type: Boolean
If this parameter is true, the code in the OnInsert Trigger is executed. If this parameter is false, the code in the OnInsert trigger is not executed. The default value is false.
Records are uniquely identified by the values in primary key fields. The C/SIDE Database Management System (DBMS) checks the primary key for the table before it inserts a new record.
If the table contains an auto-increment field, the auto-increment feature is used if the record contains a zero value in that field. The auto-increment feature enters the new value into the field as part of the insert.
If the auto-increment field contains a non-zero value, that value is inserted into the table and the auto-increment feature is not used. If the value in the auto-increment field is greater than the last auto-increment value in the table, the next auto-increment value that is entered into the table will be greater than the value in the field that you just inserted. If the value in the auto-increment field already exists in the table, a run-time error occurs.
This example shows how to use the INSERT function without a return value.
Customer.INIT Customer."No." := '1120'; Customer.INSERT;
If customer 1120 already exists, a run-time error occurs.
This example requires that you create the following variable and text constants in the C/AL Globals window.
| Variable name | DataType | Subtype |
|---|---|---|
|
CustomerRec |
Record |
Customer |
| Text constant name | ENU value |
|---|---|
|
Text000 |
Customer no: %1 inserted. |
|
Text001 |
Customer no: %1 already exists. |
CustomerRec.INIT CustomerRec."No." := '1120'; If CustomerRec.INSERT THEN MESSAGE(Text000, CustomerRec."No.") ELSE MESSAGE(Text001, CustomerRec."No.");
No run-time error occurs if customer 1120 already exists.