
Greetings,
I've written some custom code to create invoices for a specific situation. I'm using the code pasted below. I've noticed that the SalesParmUpdate record is reused and the related SalesParmTable rows are changed whenever my customization is executed. It does not seem to be the case with what SalesEditLines perform, as the parmId is always incremented. I haven't seen any "closing" method which must be done after SalesFormLetter.run() or clean-up process.
So basically, if anyone knows, am I missing some lines which prevent parmId to be reused or is it meaningless and can be disregarded?
private void createInvoice(Query _query, TransDate _invoiceDate, SalesUpdate _salesUpdate)
{
SalesFormLetter salesFormLetter;
QueryRun queryRun;
ParmId parmId;
queryRun = new QueryRun(_query);
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.specQty(_salesUpdate);
salesFormLetter.chooseLinesQuery(queryRun);
salesFormLetter.transDate(_invoiceDate);
salesFormLetter.printFormLetter(false);
salesFormLetter.chooseLines();
salesFormLetter.SumBy(AccountOrder::Account);
salesFormLetter.reArrange(false);
parmId = salesFormLetter.parmId();
salesFormLetter.run();
}
AX 2012 cu3 release 8
Regards,
Eric
*This post is locked for comments
I have the same question (0)Greetings,
Instead of using SalesFormLetter, I create a SalesFormLetter_invoice object directly and force LoadFromSysLastValue to false. Default behaviour from SalesFormLetter is set to true. So far it seems to be holding up. I'll check, I may have a few useless initXXXX() lines, but it looks like this if anyone runs into a similar situation:
private void createInvoice(Query _query, TransDate _invoiceDate, SalesUpdate _salesUpdate)
{
SalesFormLetter_invoice letter = new salesFormLetter_invoice();
QueryRun queryRun = new queryRun(_query);
letter.initParmDefault();
letter.parmLoadFromSysLastValue(false);
letter.init();
letter.specQty(_salesUpdate);
letter.chooseLinesQuery(queryRun);
letter.transDate(_invoiceDate);
letter.printFormLetter(false);
letter.chooseLines();
letter.SumBy(AccountOrder::Account);
letter.reArrangeNow(true);
letter.reArrange(false);
letter.run();
}