更新同一表

时间:2017-02-23 11:03:41

标签: axapta dynamics-ax-2012 x++

我想更新多个SalesQuotationLines匹配报价ID X.

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

salesQuotationLine.selectForUpdate(true);

if(salesQuotationLine) {

 ttsBegin;

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

ttscommit;

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

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

2 个答案:

答案 0 :(得分:2)

您可以使用此代码:

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;

我希望能够解决这个问题。

答案 1 :(得分:0)

Dynanics AX 2012提供了使用X ++ SQL语句来提高性能的方法。此选项为update_recordset,使您可以在一次到服务器的行程中更新多行:

update_recordset salesQuotationLine
setting
    Field = newFieldValue
where salesQuotationLine.quotationId == quotationId;
相关问题