Modifies a record in a C/SIDE table.
[Ok :=] Record.MODIFY([RunTrigger]) |
Parameters
- Record
-
Type: Record
The record that you want to modify.
- RunTrigger
-
Type: Boolean
Specifies whether to run the C/AL code in the OnModify Trigger.
If this parameter is true, then the code will be executed. If this parameter is false (default), then the code will not be executed.
Property Value/Return Value
Type: Boolean
true if the record was modified; otherwise, false.
If you omit this optional return value and if the record cannot be found, then a run-time error occurs. If you include the return value, then you must handle any errors.
Remarks
Select the record that you want to replace by using the primary key fields. The record's current key and filters do not affect the operation.
In multiuser environments, another application could modify the record between the time that you read the record and when you attempt to modify it. The C/SIDE Database Management System (DBMS) automatically watches for this. If a conflict occurs, then it cancels the MODIFY function and displays an error message.
If you are running Microsoft Dynamics NAV with Microsoft SQL Server and if different threads in the code modify a record, then you must refresh the value of the record variable before you edit the record again. Otherwise, you get the following error:
Another user has modified the record for this <Table Name> after you retrieved it from the database.
Enter your changes again in the updated window, or start the interrupted activity again.
You can use the GET Function (Record) to refresh the record variable. Example 2 shows how to do this.
Example 1
This example requires that you create the following variables and text constants in the C/AL Globals window.
Variable name | DataType | Subtype |
---|---|---|
CustomerRec |
Record |
Customer |
No1 |
Integer |
|
No2 |
Integer |
|
Text constant | ENU value |
---|---|
Text000 |
The customer no. %1 is:\ |
Text001 |
Now customer no. %1 is:\ |
Copy Code | |
---|---|
// Find customer. CustomerRec.FIND('-'); // Display name. MESSAGE(Text000 + '%2', CustomerRec."No.", CustomerRec.Name); // Modify customer name. CustomerRec.Name := 'Progressive Home Furnishings'; CustomerRec.MODIFY; // Display new name. MESSAGE(Text001 + '%2', CustomerRec."No.", CustomerRec.Name); |
Messages that are similar to the following are displayed:
The customer no. AAA 1050 is:
AAA Furniture Manufacturing
Now customer no. AAA 1050 is:
Progressive Home Furnishings
Example 2
In this example, you create a Line table and a Header table. The Line table has the following fields:
Field | DataType | Length |
---|---|---|
Code |
Code |
10 |
HeaderCode |
Code |
10 |
Value |
Text |
30 |
The Header table has the following fields.
Field | DataType | Length |
---|---|---|
Code |
Code |
10 |
Value |
Text |
30 |
The Header table also has a Change function.
First, you insert a record into the Line table. Then, you call a Header table function called Change, which modifies the record in the Line table that you inserted. After the Header.Change function, you must refresh the Line variable before you call any functions that edit this record again, such as MODIFY, MODIFYALL, DELETE, DELETEALL, or RENAME.
This example requires that you create the following variables in the C/AL Globals window.
Variable name | DataType | Subtype |
---|---|---|
Line |
Record |
Line |
Header |
Record |
Header |
Copy Code | |
---|---|
Line.Code := '4'; Line.HeaderCode := 'M'; Line.Value := 'Value 4'; Line.INSERT; Header.Change Line.GET(Line.Code); // Refresh the Line variable. Line.Value := 'New value'; Line.MODIFY(TRUE); |
If you omit the Line.GET(Line.Code);
statement and
you are running Microsoft Dynamics NAV with Microsoft SQL Server,
then a run-time error occurs.
See Also
© 2010 Microsoft Corporation. All rights reserved.