hi,
I am trying to create an invoice from multiple sales orders. Unfortunately, without success. Could someone look at the code and suggest how to solve this?
[SysODataAction('InVoice posting', false), SysODataCollectionAttribute('_salesId', Types::String)]
public static str CTS_PostInvoice(str _salesId)
{
//_salesId = "SO11214,SO11215,SO11216"
salesFormLetter FormLetter;
FormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
Query query = new Query(queryStr(MySalesTableQuery));
QueryBuildDataSource qbd = query.dataSourceTable(tableNum(SalesTable));
QueryBuildRange qbr = qbd.addRange(fieldNum(SalesTable, SalesId));
qbr.value(_salesId);
SysQueryRun queryRun = new SysQueryRun(query);
FormLetter.chooseLinesQuery(queryRun);
FormLetter.transDate(systemdateget());
FormLetter.specQty(SalesUpdate::PackingSlip);
FormLetter.sumBy(AccountOrder::Account);
FormLetter.showQueryForm(false);
FormLetter.printFormLetter(true);
FormLetter.chooseLines();
FormLetter.run();

I checked in the debugger and the problem occurs in the FormLetter.chooseLines() line;
debug error message:
Microsoft.Dynamics.Ax.Xpp.ErrorException
HResult=0x80131500
Message=Update has been canceled.
Source=Dynamics.AX.ApplicationSuite
StackTrace:
at Dynamics.AX.Application.FormletterParmData.`catchAll()
at Dynamics.AX.Application.FormletterParmData.catchAll()
at Dynamics.AX.Application.FormletterParmData.`createData(Boolean _append, Boolean @_append_IsDefaultSet)
at Dynamics.AX.Application.FormletterParmData.createData(Boolean _append, Boolean @_append_IsDefaultSet)
at Dynamics.AX.Application.FormletterParmData.createData(Boolean _append)
at Dynamics.AX.Application.SalesFormletterParmDataInvoice.`createData(Boolean _append, Boolean @_append_IsDefaultSet)
at Dynamics.AX.Application.SalesFormletterParmDataInvoice.createData(Boolean _append, Boolean @_append_IsDefaultSet)
at Dynamics.AX.Application.SalesFormletterParmDataInvoice.createData(Boolean _append)
at Dynamics.AX.Application.SalesFormletterParmData.`chooseLinesFromContract(Object[ _inputContract)
at Dynamics.AX.Application.SalesFormletterParmData.chooseLinesFromContract(Object[ _inputContract)
at Dynamics.AX.Application.SalesFormLetter.`chooseLines(Boolean _append, Boolean _directDeliveryUpdate, Boolean @_append_IsDefaultSet, Boolean @_directDeliveryUpdate_IsDefaultSet)
at Dynamics.AX.Application.SalesFormLetter.SalesFormLetterCoCHelper.`chooseLines(SalesFormLetter instance, Boolean arg0, Boolean arg1, Boolean , Boolean )
at Dynamics.AX.Application.SalesFormLetterRevRec_Extension.chooseLines(SalesFormLetter this, Boolean _append, Boolean _directDeliveryUpdate)
at Dynamics.AX.Application.SalesFormLetter.SalesFormLetterCoCHelper.`chooseLines(SalesFormLetter instance, Boolean arg0, Boolean arg1, Boolean , Boolean )
at Dynamics.AX.Application.SalesFormLetter.chooseLines(Boolean _append, Boolean _directDeliveryUpdate, Boolean @_append_IsDefaultSet, Boolean @_directDeliveryUpdate_IsDefaultSet)
at Dynamics.AX.Application.CTS_SalesEntity.`CTS_PostInvoice(String _salesId) in xppSource://Source/xxx\AxDataEntityView_CTS_SalesEntity.xpp:line 73
at Dynamics.AX.Application.SalesFormLetter.chooseLines()
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[ parameters)