Table method insert() in D365

X++ Programming Language >   D365 Table >   Table Methods  

Long Question

5827


Answer:

Insert() and update() are rarely overridden. However, if you need to ensure a field has a certain value upon inserting a record, you can initialize your field before calling super() in insert().  Some special cases might also require overriding these methods; for example, if you need to synchronize the content of a saved record to another table.

Using X++ for entering data requires a bit more than using the user interface like forms. Only the table methods called will be executed.

Example: In this example, let’s see how to use the table methods to insert a record in MyFirstTable.



static void DataDic_InsertRecord(Args _args)
{
    MyFirstTable myFirstTable;
    
    ttsbegin;
    myFirstTable.initValue();
    myFirstTable.accountNum = "100";
    myFirstTable.custName = "Alt. customer id 100";
    myFirstTable.CurrencyCode = "USD";
    if (myFirstTable.validateWrite())
        myFirstTable.insert();
    ttscommit;
}


InitValue() is called and will set the value of the field custGroupId. The record will only be inserted if validateWrite() is true. As all mandatory fields have a value, the record will be inserted.

Instead of calling insert() you could call write(). This will update an existing record, but if the record does not exist, a new record will be inserted.

The select keywords delete_from, insert_recordset and update_recordset make only one call to the database from the client when processing multiple records.


This Particular section is dedicated to Question & Answer only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.