2017-02-23 65 views
0

多条记录我要更新多台SalesQuotationLines匹配报价ID为X更新在同一个表

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

salesQuotationLine.selectForUpdate(true); 

if(salesQuotationLine) { 

ttsBegin; 

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

ttscommit; 

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

我怎样才能确保所有符合QuotationID的记录都被更新?

回答

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; 

我希望砧木的问题。

0

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

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