DELETE Function (Record)

Deletes a record in a C/SIDE table.


[Ok :=] Record.DELETE([RunTrigger])

Parameters

Record

Type: Record

The record to be deleted. The record itself does not change.

RunTrigger

Type: Boolean

This optional parameter specifies whether to run the C/AL code in the OnDelete Trigger.

If this parameter is true, then the code in the OnDelete trigger will be executed. If this parameter is false (default), then the code in the OnDelete trigger will not be executed.

The default value is false.

Type: Boolean

true if the record was deleted. false if the record was not deleted because it could not be found in the table or if the user did not have the correct permissions. If the C/AL code terminates, false is returned.

If the record does not exist and you do not include a return value, the function will terminate with a run-time error.

The current key and any filters on the record have no effect on this operation. The record to delete is identified by the values in its primary key.

In a multiuser environment, another application can delete the record from the table after you read the record and before you try to delete it. The Database Management System automatically detects such a situation, which causes the DELETE function to fail with a run-time error.

To prevent this situation, you can lock the table while you are using it with the LOCKTABLE Function (Record).

These examples show how to use the DELETE function. The first example does not use the return value from the DELETE function. This means that a run-time error occurs if the record to be deleted cannot be found.

The second example shows how you can handle errors using the return value.

These examples require that you create the following variables and text constants in the C/AL Globals window.

Variable name DataType Subtype

CustomerRec

Record

Customer

Text constant name ENU Value

Text000

The customer has been deleted.

Text001

The customer could not be found.

// Without using the return value:
CustomerRec."No." := '100';
CustomerRec.DELETE;
// Using the return value:
CustomerRec."No." := '100';
IF CustomerRec.DELETE THEN
  MESSAGE(Text000)
ELSE
  ERROR(Text001);

Community Additions

ADD
Show: