Difference between Insert() vs doinsert(), update() vs doinsert(),delete() vs dodelete() methods of Axapta
1) Update() vs doupdate() method:
The doUpdate table method updates the current record with the contents of the buffer. This method also updates the appropriate system fields.
The doUpdate method should be used when the update method on the table is to be bypassed. Suppose you have overridden the update method of the table but sometime there is a situation when you don't want the code written in the overridden update method to be executed and at the same time want any selected record of that table to be updated. In such situation you should call the table.doupdate() method instead of table.update() method.
CustTable custTable;
ttsBegin;
select forUpdate custTable
where custTable.AccountNum == '4000';
custTable.CreditMax = 5000;
custTable.update();
ttsCommit;
ttsBegin;
select forUpdate custTable
where custTable.AccountNum == '4000';
custTable.CreditMax = 5000;
custTable.update();
ttsCommit;
The example selects the table custTable for update. Any records with the AccountNum equal to 4000 are updated (in this case only one). The CreditMax field is changed to 5000.
static void Job1(Args _args)
{
CustTable custTable;
ttsBegin;
select forUpdate custTable
where custTable.CreditMax == '3000';
if (custTable)
{
custTable.CreditMax = 1000;
custTable.doUpdate();
}
ttsCommit;
}
{
CustTable custTable;
ttsBegin;
select forUpdate custTable
where custTable.CreditMax == '3000';
if (custTable)
{
custTable.CreditMax = 1000;
custTable.doUpdate();
}
ttsCommit;
}
2) Insert() vs doinsert() method :
The insert method updates one record at a time.
CustTable custTable;
;
ttsBegin;
select forUpdate custTable;
custTable.AccountNum = '5000';
custTable.insert();
ttsCommit;
;
ttsBegin;
select forUpdate custTable;
custTable.AccountNum = '5000';
custTable.insert();
ttsCommit;
The doInsert method generates values for the RecId field and other system fields, and then inserts the contents of the buffer into the database. This operation is used when the insertmethod on the table is to be bypassed.
ttsBegin;
myTable.name = 'Flemming Pedersen';
myTable.value = 100;
myTable.doInsert();
ttsCommit;
myTable.name = 'Flemming Pedersen';
myTable.value = 100;
myTable.doInsert();
ttsCommit;
3) delete() vs dodelete() method:
The delete method can be overridden, for example, to add extra validation before records are deleted.
If you override the delete method, the original version of the delete method can be executed instead by calling the doDelete method. It is equivalent to calling super() in the delete method; doDeleteexecutes the base version of the delete method.
ttsBegin;
while select forUpdate myTable
where myTable.AccountNum == '1000'
{
myTable.delete();
}
ttsCommit;
ttsBegin;
while select forUpdate myTable
where myTable.AccountNum >='200';
{
myTable.doDelete();
}
ttsCommit;
The delete method can be overridden, for example, to add extra validation before records are deleted.
If you override the delete method, the original version of the delete method can be executed instead by calling the doDelete method. It is equivalent to calling super() in the delete method; doDeleteexecutes the base version of the delete method.
ttsBegin;
while select forUpdate myTable
where myTable.AccountNum == '1000'
{
myTable.delete();
}
ttsCommit;
ttsBegin;
while select forUpdate myTable
where myTable.AccountNum >='200';
{
myTable.doDelete();
}
ttsCommit;