Mark Van
Mark Van

Reputation: 281

Update multiple records in same table

I want to update multiple SalesQuotationLines the match Quotation Id X.

salesQuotationLine = salesQuotationLine::find(quotationId,true);

salesQuotationLine.selectForUpdate(true);

if(salesQuotationLine) {

 ttsBegin;

SalesQuotationLine.Field = newFieldValue;
salesQuotationLine.update();

ttscommit;

The problem is, this is only updating the first record that is found within the find method.

How can I make sure, all records that match the QuotationID are being updated?

Upvotes: 1

Views: 5439

Answers (2)

ulisses
ulisses

Reputation: 1569

you can use this code:

while select forupdate salesQuotationLine 
where salesQuotationLine.quotationId == quotationId 
{
    salesQuotationLine..Field = newFieldValue;
    ttsbegin;
    salesQuotationLine.update();
    ttscommit;
}

Or can Use _update_recordset_

ttsbegin;
update_recordset salesQuotationLine
setting
Field = newFieldValue
where salesQuotationLine.quotationId == quotationId 
ttscommit;

I hope to understock the question.

Upvotes: 3

Aliaksandr Maksimau
Aliaksandr Maksimau

Reputation: 2281

Dynanics AX 2012 provides way to use X++ SQL statements to enhance performance. This option is update_recordset which enables you to update multiple rows in a single trip to the server:

update_recordset salesQuotationLine
setting
    Field = newFieldValue
where salesQuotationLine.quotationId == quotationId;

Upvotes: 0

Related Questions