更新同一 table 中的多个记录

Update multiple records in same table

我想更新多个 SalesQuotationLines 以匹配报价单 ID X。

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

salesQuotationLine.selectForUpdate(true);

if(salesQuotationLine) {

 ttsBegin;

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

ttscommit;

问题是,这只是更新在 find 方法中找到的第一条记录。

我如何确保所有匹配 QuotationID 的记录都被更新?

您可以使用此代码:

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

或者可以使用_update_recordset_

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

希望能少提问题

Dynanics AX 2012 提供了使用 X++ SQL 语句来增强性能的方法。此选项是 update_recordset,它使您能够在一次访问服务器的过程中更新多行:

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