Editar

Compartir vía


RecordRef.Insert() Method

Version: Available or changed with runtime version 1.0.

Inserts a record into a table without executing the code in the OnInsert trigger.

Syntax

[Ok := ]  RecordRef.Insert()

Parameters

RecordRef
 Type: RecordRef
An instance of the RecordRef data type.

Return Value

[Optional] Ok
 Type: Boolean
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

Records are uniquely identified by the values in primary key fields. The 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 method works the same as the Insert Method (Record).

Example

The following example opens a table 18 (Customer) with a RecordRef variable that is named CustomerRecref. The Field Method (RecordRef) creates a FieldRef variable that is named MyFieldRef for the field. The Init Method (RecordRef) initializes the values in the fields by using default values and then the Insert method inserts a new record. The new record is 1120. This is the primary key for the new record.

Note

In this example, the Init method is called before the primary key is assigned a value. The Init method does not initialize primary key fields. Therefore calling the Init Method (RecordRef) before or after you assign values to the primary key field does not make any difference.

var
    CustomerRecref: RecordRef;
    MyFieldRef: FieldRef;
    Text000: Label 'The value of the field after you insert the record is %1.';
begin 
    CustomerRecref.Open(18);  
    MyFieldRef := CustomerRecref.Field(1);  
    CustomerRecref.Init();  
    MyFieldRef.Value := '1120';  
    CustomerRecref.Insert();  
    Message(‘%1’, MyFieldRef.Value);  
end;

RecordRef Data Type
Get Started with AL
Developing Extensions