Data manipulation Dynamics 365 Finance and Operations

//This will insert a new record into a sample MyCustomerTable table. The only mandatory field that is set on this table is AccountNumber.

Insert method

private void AddCustomer()
{
MyCustomerTable myCustomerTable;
ttsBegin;
select forUpdate myCustomerTable;
myCustomerTable.AccountNumber = "1234";
//The new record will have the account number 1234.
myCustomerTable.insert();
ttsCommit;
}

Update method

//This will update the record where the AccountNumber field is set to 1234 by adding more information in the CustomerName field.

private void UpdateCustomer()
{
MyCustomerTable myCustomerTable
ttsBegin;
select forUpdate myCustomerTable
where myCustomerTable.AccountNumber == "1234";
//Now we will update the CustomerName field to be Sally
myCustomerTable.CustomerName = "Sally";
myCustomerTable.update();
ttsCommit;
}

Delete method

//This will delete the record from the MyCustomerTable table where the AccountNumber field is set to 1234.

private void DeleteCustomer()
{
ttsBegin;
while select forUpdate myCustomerTable
where myCustomerTable.AccountNumber == "1234"
{
myCustomerTable.delete();
}
ttsCommit;
}

The update_recordset can update multiple fields on a table. You can also specify a where clause to determine what records are updated. The following is an example of an update_recordset where you declare the table and call the update_recordset to update the customer PaymMode and Currency fields only for the customers with a CustGroup field that equals “US.” Keep in mind that if the update method is overridden, the update_recordset will call the update method one at a time instead of all at once.

CustTable;
Update_recordset custTable
Setting
PaymMode = 'Check',
Currency = 'USD'
Where custTable.CustGroup == 'US';

The delete_from method is like the update_recordset. You can delete multiple records at the same time from a table, and you can use a where clause to determine which records to delete. In the following example, the table is declared and then the delete_from is called to delete all the records where the customer’s CustGroup field equals “US.”

CustTable;
Delete_from custTable
Where custTable.CustGroup == 'US';

Insert_recordset lets you insert multiple records from one table into another table. You can use a where clause to determine which records to insert, and you can use variables to insert. In the following example, the table that will be inserted into and the table that you are pulling data from are declared. The insert_recordset is then called to insert data into the fields that are listed in parentheses. The fields from the staging table are then called in the order that the fields were listed in the parentheses. Now, those fields will be inserted into the CustTable where the staged customer’s CustGroup field equals “US.”

CustTable custTable;
StagingCustTable stagingCustTable;

Insert_recordset custTable (accountNum, custGroup, paymMode, currency)
Select stagingAccountNum, stagingCustGroup, stagingPaymMode, stagingCurrency
From stagingCustTable
Where stagingCustTable.stagingCustGroup == 'US';

Leave Comment

Your email address will not be published. Required fields are marked *