Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Issue carrying modified sales lines to posted sales invoice lines

Posted on by 2
Hello All,
 
I am currently working on a solution that entails changing the OOB /Line Amount/ field to adjust based off of commission %. This amount is modified correctly on the sales lines, however when I preview the sales order posting, or post the sales order - the adjusting line value /Line Amount/ Changes back to what it was prior to the modification.
 
I have been looking through the sales-post code unit trying to use integration events to no-avail , has anyone worked with anything of this nature before that could offer solutions on how to take the current values from the sales lines to the G/L Entries and Posted Sales invoice lines. Rather than them recalculating the base values?
 
TIA!
 
Here are the values I'm modifying on the sales line when commission % is modified - 
I want these changed values to carry over to the Posted Sales Invoice Lines.
modify(/GCB Commission %/)
        {
            Trigger OnAfterValidate()
            begin
                if /GCB Commission %/ = 0 then begin
                    /Rep Order Amount/ := 0;
                    /Line Amount/ := /Unit Price/ * /Quantity/;
                    /Amount Including VAT/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Amount/ := /Unit Price/ * /Quantity/;
                    /VAT Base Amount/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Outstanding Amount/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Outstanding Amount (LCY)/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    // /Amount Including VAT/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
 
                end
                else begin
                    /Rep Order Amount/ := /Quantity/ * /Unit Price/;
                    /Line Amount/ := (/Unit Price/ * /Quantity/) * (/GCB Commission %/ / 100);
                    /Amount Including VAT/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Amount/ := (/Unit Price/ * /Quantity/) * (/GCB Commission %/ / 100);
                    /VAT Base Amount/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Outstanding Amount/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
                    /Outstanding Amount (LCY)/ := /Line Amount/ + (/Line Amount/ * /VAT %/ / 100);
 
                end;
            end;
        }
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,647 Super User 2024 Season 2 on at
    Issue carrying modified sales lines to posted sales invoice lines
    Hi, please do not use the assignment operator (:=), use the following method. Some key fields are hidden in the table and will change along with the validation of other fields. However, if you only use the assignment operator, the code in the field validate trigger will not be executed. This should be the problem.
    Record.Validate(Any [, Any]) Method
     
     
    Hope this helps.
    Thanks.
    ZHU

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans