Update_recordset

The update_recordset operator can be used to update a chunk of records in
a table in one database operation. As with the insert_recordset operator
the update_recordset is very efficient because it only needs to call an update in
the database once.
The syntax for the update_recordset operator can be seen in the next example:

static void Update_RecordsetExmple(Args _args)
{
CarTable carTable;
;
info(“BEFORE UPDATE”);
while select carTable
where carTable.ModelYear == 2007
{
info(strfmt(“CarId %1 has run %2 miles”,
carTable.CarId, carTable.Mileage));
}
update_recordset carTable
setting Mileage = carTable.Mileage + 1000
where carTable.ModelYear == 2007;
info(“AFTER UPDATE”);
while select carTable
where carTable.ModelYear == 2007
{
info(strfmt(“CarId %1 has now run %2 miles”,
carTable.CarId, carTable.Mileage));
}
}
When this Job is executed it will print the following messages to the Infolog:
Notice that no error was thrown even though the Job didn’t use selectforupdate,
ttsbegin, and ttscommit statements in this example. The selectforupdate is
implicit when using the update_recordset, and the ttsbegin and ttscommit are
not necessary when all the updates are done in one database operation. However, if
you were to write several update_recordset statements in a row, or do other checks
that should make the update fail, you could use ttsbegin and ttscommit and force
a ttsabort if the checks fail.
Consider modifying the previous example so that it gets a transaction scope and a
check that makes sure to break the update as shown below:
static void Update_RecordsetExmpleTts(Args _args)
{
CarTable carTable;
// Change the check to false to make the
// transaction go through
boolean check = true;
;
info(“BEFORE UPDATE”);
while select carTable
where carTable.ModelYear == 2007
{
info(strfmt(“CarId %1 has run %2 miles”,
carTable.CarId, carTable.Mileage));
}
ttsbegin; // Added ttsbegin
update_recordset carTable
setting Mileage = carTable.Mileage + 1000
where carTable.ModelYear == 2007;
if (check)
throw info(“This is a test”);
ttscommit; // Added ttscommit
info(“AFTER UPDATE”);
while select carTable
where carTable.ModelYear == 2007
{
info(strfmt(“CarId %1 has now run %2 miles”,
carTable.CarId, carTable.Mileage));
}
}
The update will now never be committed in the database so every time you run this
Job the the result will look like the next screenshot:
Source
MicrDynamicAX2009 Started

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Dijital Dönüşümünüzü AI İle Hızlandırın

Dynamics 365 ve AI destekli çözümlerle iş süreçlerinizi optimize edin, verinizi anlamlı içgörülere dönüştürün ve büyümenizi sürdürülebilir hale getirin.

AI-Ready Enterprise Partner

Microsoft Dynamics 365 ve yapay zekâ çözümleriyle kurumsal sistemlerinizi güçlendirir, operasyonel karmaşıklığı azaltır ve geleceğe hazır bir mimari tasarlarız.

DMR Göztepe Merkez Ofis

Eğitim Mah. Hızırbey Cad. No:118/5 D:1 Kadıköy İstanbul

Marmara Üniversitesi Göztepe Kampüsü Teknopark

Tel: +90 216 470 79 49

E-posta: info@dmrbt.com

DMR Başıbüyük Ofis

Başıbüyük Mahallesi Süreyyapaşa Başıbüyük Yolu Sk. No: 4/7 Maltepe İstanbul

Marmara Üniversitesi Başıbüyük Kampüsü Teknopark

Tel: +90 216 470 79 49

E-posta: info@dmrbt.com