X++ Development ·

Understanding X++ Data Methods: Insert, Update, and Delete

A comprehensive guide to the core data manipulation methods in X++ and how to use them effectively in Dynamics 365 F&O.

By Ahmad Hasan · 5 min read

Introduction

X++ provides several methods for manipulating data in Dynamics 365 Finance & Operations. Understanding when and how to use each method is crucial for writing efficient and maintainable code.

The Insert Method

The insert() method adds a new record to the database. Here is a basic example:

public void insertExample()
{
    CustTable custTable;
    
    custTable.initValue();
    custTable.AccountNum = "1001";
    custTable.Name = "Adventure Works";
    custTable.insert();
}

The Update Method

When updating records, always use select forUpdate to lock the record:

public void updateExample(AccountNum _accountNum)
{
    CustTable custTable;
    
    select forUpdate custTable
        where custTable.AccountNum == _accountNum;
    
    if (custTable)
    {
        custTable.Name = "Updated Name";
        custTable.update();
    }
}

The Delete Method

Deleting records follows a similar pattern:

public void deleteExample(AccountNum _accountNum)
{
    CustTable custTable;
    
    select forUpdate custTable
        where custTable.AccountNum == _accountNum;
    
    if (custTable)
    {
        custTable.delete();
    }
}

Best Practices

  • Always use select forUpdate before modifying or deleting records
  • Use ttsBegin and ttsCommit for transaction control
  • Consider using RecordInsertList for bulk inserts
  • Leverage Query classes for complex data operations

Conclusion

Mastering these fundamental data methods is essential for any X++ developer working with Dynamics 365 F&O. Practice these patterns and always consider performance implications when working with large datasets.

Share this post

A

Ahmad Hasan

Microsoft Dynamics 365 & Power Platform blogger.

Related Posts

Comments