SalesFormLetter salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); SalesParmLine parmLine; SalesParmUpdate salesParmUpdate; //A SalesTable that already exists with one line unposted salesFormLetter.salesTable(initialSalesTable); salesFormLetter.transDate(invoiceDate); salesFormLetter.specQty(SalesUpdate::All); salesFormLetter.proforma(false); salesFormLetter.printFormLetter(false); salesParmUpdate = salesFormLetter.salesParmUpdate(); //Passing a NumberSequenceGroup string to a Custom field in order to allocate Invoice and Voucher num from this later salesParmUpdate.CustomNumberSequenceGroupId = numberSequenceGroup; salesFormLetter.createParmUpdateFromParmUpdateRecord(salesParmUpdate); salesFormLetter.initParmSalesTable(initialSalesTable); salesFormLetter.initParameters(salesParmUpdate, Printout::After); salesFormLetter.initLinesQuery(); //Remove lines of Sales Order that don't belong to this process while select parmLine where parmLine.ParmId == salesFormLetter.parmId() { if(!someMap.exists(parmLine.SalesLineRecId)) { parmLine.selectForUpdate(true); parmLine.delete(); } } salesFormLetter.run();
Hi @Vasileios,
Thanks for sharing the detailed context — really helpful in understanding the issue.
Since the same logic works when triggered from the UI but fails in code, and given your suspicion about SalesParmUpdate inconsistencies, a few things to consider:
SalesParmUpdate
CustomNumberSequenceGroupId
initParameters()
run()
info()
debug
salesFormLetter.salesParmUpdate().CustomNumberSequenceGroupId
SalesParmLine
Also, I highly recommend checking out this article by Gaurav Gulati: 🔗 How to debug sandbox/UAT environment in D365FO It walks you through how to attach a debugger to a sandbox/UAT environment — super helpful in scenarios like this when code behaves differently in non-dev tiers.
Let us know how it goes once you try these steps.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CA Neeraj Kumar 2,239
André Arnaud de Cal... 903 Super User 2025 Season 2
Sohaib Cheema 604 User Group Leader