web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

invoice sales order with udpated line amount

(3) ShareShare
ReportReport
Posted on by 111
i want to update lineamount (based on packing slip line amount) which is line amount - custom discount rebate.
i am unable to do it. i have tried code on salesformletterparmdata, salesformletter_invoice, salesformletterparmdatainvoice but no use.
once it update the amount but while posting it goes default vlaues in invoicing and voucher transactions. miss match error of debit and credit
please guide me.
i have updated line maount on pakcing slip as it we put manually qty and modify line amount based on that.
but i am facing issue in invoicing
thats the requirements as (invoice sales order with deduction of some rebate discount) that would be same in invoicing sales order and transactions too. we can invoice partial sales order too.
Categories:
I have the same question (0)
  • Saalim Ansari Profile Picture
    666 on at
    Hi @Dyn_US
     

    I understand your issue – you're trying to invoice a sales order where the line amount should be based on the packing slip line amount minus a custom rebate, but during invoicing, default values are used, causing debit/credit mismatch errors.

    Here’s the important part: even if you update the SalesLine or packing slip line, the system uses SalesParmLine during invoice posting. This is where the line amount gets recalculated, unless you explicitly override it.

    To solve this:

    • Pass your custom rebate logic from SalesLine to SalesParmLine.

    • Make sure the adjusted line amount is applied correctly before posting the invoice.

    If you can share the code where you're modifying the amount, I’d be happy to review it and guide you further.

     
    Hope this helps
    Saalim
  • Dyn_US Profile Picture
    111 on at
    hi @Saalim Ansari
    thank you for your reply. i am updating to line amount in salesparmline table its working till packing slip. but when i do automatically invoicing it picks default line from slaesline table and do invoice. when i update line amount of table sales parm line while automatically invoicing then there is no effect on voucher transaction of invoice journal transaction . 
  • Saalim Ansari Profile Picture
    666 on at
    Hi,
     

    Could you please provide more details so we can assist you better?

    It would be helpful if you could include:

    • Code snippets (using the "Insert code snippet" button)

    • Screenshots of the issue (using the "Insert image" button)

    • Error messages or stack traces if available

    The more context you provide, the easier it will be for us to troubleshoot and offer a solution.

     

  • Dyn_US Profile Picture
    111 on at
    [ExtensionOf(classStr(SalesPackingSlipJournalPost))]
    final class SalesPackingSlipJournalPost_Extension
    {
       public void postJournalPost()
        {
            next postJournalPost();
            SalesTable salesTable = custPackingSlipJour.salesTable();
            SalesLine sales_line;
            select * from sales_line
                where sales_line.SalesId == salesTable.SalesId;
    
            SalesPackingSlipJournalPost::salesOrderInvoiceByLine(sales_line);
    
        }
    
        Public static void salesOrderInvoiceByLine(SalesLine    _salesline) //it doing selected delivery invoicing but not deducting discount
            {
                salesFormLetter         salesFormLetter;
                salesFormletterParmData salesFormLetterParmData;
                salesParmUpdate         salesParmUpdate;
                salesParmTable          salesParmTable;
                salesParmLine           salesParmLine, salesparmlinelast,packingParmLine;
                salesTable              salesTable;
                SalesLine   _line;
                ttsbegin;
                salesTable  = salesTable::find(_salesline.SalesId);
                salesFormLetterParmData = salesFormletterParmData::newData(DocumentStatus::Invoice, VersioningUpdateType::Initial);
    
                salesFormLetterParmData.parmOnlyCreateParmUpdate(true);
                salesFormLetterParmData.createData(false);
                salesParmUpdate = salesFormLetterParmData.parmParmUpdate();
    
                salesParmTable.clear();
                salesParmTable.TransDate                = _salesline.ReceiptDateRequested;
                salesParmTable.Ordering                 = DocumentStatus::Invoice;
                salesParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
                salesParmTable.salesId                  = salesTable.salesId;
    
                salesParmTable.salesName                = salesTable.salesName;
                salesParmTable.DeliveryName             = salesTable.DeliveryName;
                salesParmTable.DeliveryPostalAddress    = salesTable.DeliveryPostalAddress;
                salesParmTable.CustAccount              = salesTable.CustAccount;
                salesParmTable.CurrencyCode             = salesTable.CurrencyCode;
                salesParmTable.InvoiceAccount           = salesTable.InvoiceAccount;
                salesParmTable.ParmId                   = salesParmUpdate.ParmId;
                salesParmTable.insert();
    
                if (_salesline)
                {
                    salesParmLine.InitFromsalesLine(_salesline);
                    salesParmLine.DeliverNow    = _salesline.SalesQty;
                    salesParmLine.ParmId        = salesParmTable.ParmId;
                    salesParmLine.TableRefId    = salesParmTable.TableRefId;
                    salesParmLine.setQty(DocumentStatus::Invoice, false, true);
                    salesParmLine.setLineAmount(_salesline);
                    salesParmLine.insert();
                }
                ttscommit;
    
         
    
                select * from salesparmlinelast //GET LAST packing LINES
                order by salesparmlinelast.PARMiD DESC
                    where salesparmlinelast.origsalesid == salesTable.SalesId
                   join SalespARMTABLE
                  where salesparmlinelast.ParmId == salesParmTable.parmid
                && salesParmTable.Ordering == DocumentStatus::PackingSlip;
    
    
    
                select * from _line
                where _line.RecId == salesParmLine.SalesLineRecId;
    
    
                real qty = _line.SalesQty;
            real remainders = qty - salesparmlinelast.DeliverNow;
    
    
                ttsbegin;
                salesParmLine.selectForUpdate(true);
            salesParmLine.DeliverNow = salesparmlinelast.DeliverNow;
                salesParmLine.RemainAfter =remainders;
                salesParmLine.RemainAfterInvent =remainders;
            salesParmLine.InventNow = salesparmlinelast.DeliverNow;
            salesParmLine.LineAmount = salesparmlinelast.LineAmount;
               salesParmLine.doUpdate();
                ttscommit;
    
                salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
                salesFormLetter.transDate(_salesline.ReceiptDateRequested);
                salesFormLetter.proforma(false);
                salesFormLetter.specQty(salesUpdate::all);
                salesFormLetter.salesTable(salesTable);
                salesFormLetter.parmId(salesParmTable.ParmId);
                salesFormLetter.salesParmUpdate(salesFormLetterParmData.parmParmUpdate());
                salesFormLetter.run(); //error here at this line
            
    
        }
    
    }  

    hi 
    erorr are 
    Posting
    Posting
    Sales order: 004835
    Posting
    Posting
    Sales order: 004835
    Voucher INV-10000774
    The transactions on voucher INV-10000774 do not balance as per 5/22/2025. (accounting currency: -40.00 - reporting currency: -40.00)
    Voucher transactions
    Voucher INV-10000774, date 5/22/2025, account 140100--, transaction currency amount 374.96, accounting currency amount 374.96, reporting currency amount 374.96, currency USD, text
    Voucher INV-10000774, date 5/22/2025, account 500150----, transaction currency amount -374.96, accounting currency amount -374.96, reporting currency amount -374.96, currency USD, text
    Voucher INV-10000774, date 5/22/2025, account 140100--, transaction currency amount -374.96, accounting currency amount -374.96, reporting currency amount -374.96, currency USD, text
    Voucher INV-10000774, date 5/22/2025, account 500100----, transaction currency amount 374.96, accounting currency amount 374.96, reporting currency amount 374.96, currency USD, text
    Voucher INV-10000774, date 5/22/2025, account 401100----, transaction currency amount -400.00, accounting currency amount -400.00, reporting currency amount -400.00, currency USD, text
    Voucher INV-10000774, date 5/22/2025, account 130100--, transaction currency amount 360.00, accounting currency amount 360.00, reporting currency amount 360.00, currency USD, text
    Posting has been canceled.

    360 is a line amount of sales parm line after deduction of discount 40
    now in transactions, there is difference of 40 credit and debit
    thats the isse 
    please guide me 

     
  • Suggested answer
    Saalim Ansari Profile Picture
    666 on at
    Hi,
     
    Thanks for the detailed input — this issue clearly stems from manual creation of SalesParmLine and line amounts without handling discounts properly, which leads to an unbalanced voucher during invoice posting
     
    Your custom code sets LineAmount directly using setLineAmount(_salesline), but this does not account for line-level or header-level discounts. This causes the final accounting entries to not balance (i.e., debit ≠ credit), and AX/D365 throws the voucher balancing error.
     
    Here, there's a 40.00 credit more than debit, caused by applying discount at GL level but not reducing the line amount in the invoice logic.
     
    To handle discounts correctly, you must ensure the LineAmount in SalesParmLine matches the post-discount value of the sales line.

     

    Does Dynamics 365 Finance & Operations (D365FO) support partial invoicing?

    Yes, D365FO natively supports partial (selected delivery) invoicing for sales orders.

    • You can invoice specific lines, partial quantities, or even specific deliveries using the "Posting" > "Invoice" > "Select packing slip" feature from the sales order.

    • This works out-of-the-box without customization — the framework handles discount allocation, financial dimensions, inventory impact, and voucher generation automatically.

    So if your intention is to partially invoice the sales order, D365FO fully supports it.


    However, the moment you step into custom invoicing logic, you take responsibility for applying all validations, discounts, and posting logic properly.

  • Dyn_US Profile Picture
    111 on at
    i know the sales order can be partially post but the problem is; where i have to update line amount in above code. i am getting error of transaction vouchers. kindly can you tell me specific class where i have to update it so it go to transactions too.
  • Saalim Ansari Profile Picture
    666 on at

    You will need to revise your code based on your requirement.

    If the objective is to update the SalesParmLine.LineAmount based on custom rebate fields, the correct place to implement this logic is in the modifiedFieldValue method at the table level of SalesParmLine.

    I looked into the issue with the invoice posting error — specifically the voucher imbalance caused after updating the LineAmount in the SalesParmLine during automatic invoicing.

    The root cause is that modifying only LineAmount doesn’t trigger recalculations for discounts and taxes, which are essential for generating accurate accounting entries. The invoice process still references values from SalesLine, including the original amount and pricing logic.

     

    You can refer to this blog post for handling tax calculations based on updated line amounts:
    Calculate Tax Amount in X++ – D365FO

    It shows how to use the Tax::calcTaxAmount() method effectively. Since you're modifying the LineAmount in SalesParmLine, it's important to also recalculate taxes accordingly. This ensures your voucher transactions remain balanced during invoice posting and avoids mismatch issues like the one you're facing.

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans