06 October 2010

Using while select firstonly to avoid validations in Dynamics Ax

static void WhileSelectInsteadoFSelect(Args _args)
{
InventTable inventTable;
;
-----General way---------
//fetch the record first
select firstonly forupdate inventtable;

//add an additional validation
if (inventTable.recid)
{
inventTable.itemName = 'newname';
inventTable.update();
}

------Alternate--------------
//prevents the extra 'if' chek
while select firstonly forupdate inventTable
{
inventTable.itemName = 'newname';
inventTable.update();
}

//can also be used for simple readonly
while select firstonly inventTable
{
Info(inventTable.ItemId);
}
}

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...