Codeunit 80 - OnBeforePostUpdateOrderLine is not called while posting Sales transaction in Extension 2.0 build
in Extension 1.0 we have raised custom event which is not working in Extension 2.0.
Event details
[EventSubscriber(ObjectType::Codeunit, 80, 'OnBeforePostUpdateOrderLine', '', false, false)]
local procedure OnBeforePostUpdateOrderLine(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line");
var
LocalSalesLine: Record "Sales Line";
begin
//this will use updated sales line while creating sales invoice lines with updated tax
message('Posted lines updated');
SalesLine.DELETEALL;
LocalSalesLine.SetRange("Document Type", SalesHeader."Document Type");
LocalSalesLine.SetRange("Document No.", SalesHeader."No.");
if LocalSalesLine.FindSet then
repeat
SalesLine := LocalSalesLine;
SalesLine.Insert;
until LocalSalesLine.Next = 0;
end;
@freddydk : also one difference found in Codeunit 80 for this event: [Scope('''Personalization''')] --> is not defined for this event. does this is a root cause for not being called from our subscription event.

Purpose of this event : update TempSalesLineGlobal with new values (in our case : update Tax amount on sales line) which will be used to create Sales Inv Line. Expected behavior : Sales Invoice line will have Amount including Tax with Tax amount updated properly. current behavior : Sales Invoice line is created without Tax amount have Amount including Tax updated properly.
We will treat this issue as an event request.
It is not clear to us why your custom event didn't fire. You should mark it as FunctionVisibility = External in C/SIDE and then regenerate your symbol files. See https://github.com/Microsoft/AL/wiki/Useful-resources
Hi @chavansachin20, If you are not using the sandbox, then could you try and see if the virtual table "Event Subscription" contains some more information why your subscriber isn't called.
@StanislawStempin , this was working in Ext 1.0 and in latest release (Extn. 2.0), this is not called which resulted in to wrong amount updated to Posted transactions (Sales invoice lines with wrong amount + tax amount)
Hi @Chavansachin20, I'm not able to reproduce the issue you are having. I create a new Event on Codeunit 80 "Sales-Post", as a local procedure with FunctionVisibility as Internal and matched the parameters. I then created a procedure next to it to invoke it which I made available for extensions. In my extension I have a page action to invoke said function and a codeunit to subscribe to this event and it works for me.
Which version of the server and the extension are you running? Have you checked if the Virtual Table "Event Subscription" contained any more information? Is there anything in the event viewer?
Hello @thpeder ,
Below are details for version :
Microsoft_Application_12.0.21229.0.app
Microsoft_System_12.0.12928.0.app

Details from Event subscription page : only OnBeforePostUpdateOrderLine event is not working properly for me.

We have other subscriptions events also on CU 80, and they all are working as expected when called from Subscription event.

Only OnBeforePostUpdateOrderLine is not called from Subscription event.
@chavansachin20 If you scroll to the right, then there is a "Error Information" column, is there anything in that?
@thpeder please see below screenshot : Error Information is blank.

@chavansachin20, Thanks for sending the screenshot. Could you try and regenerate the symbol file and download it to your project, like StanislawStempin recommended.
After changes made inside my docker for CU80, my docker is corrupted, resolving my docker issue. Once complete my changes suggested for CU80 by @StanislawStempin will test and update status here. code changes : FunctionVisibility = External in C/SIDE
@thpeder : I have followed below steps:
- applied changes to CU 80 and set FunctionVisibility = External in C/SIDE for OnBeforePostUpdateOrderLine.
- Reloaded symbols successfully.
- event subscription list (no error)

- But while accessing it from VS code getting error as below

please suggest further steps.
Hi @chavansachin20,
For your symbols to contain the new parameter you need to open C/Side with generatesymbolreference=yes and for your case probably recompile that object. You can read more about it here: Running C/SIDE and AL Side-by-Side
For the specific error in the screenshot you have flipped the type and the name, meaning it should look like SuppressCommit: Boolean, but intellisense should help you to find the parameters:

@thpeder : as you suggested, mage changes to FunctionVisibility = External in C/SIDE for OnBeforePostUpdateOrderLine. and then downloaded the symbol. but still OnBeforePostUpdateOrderLine is not called or tracked in my debugger.
@chavansachin20, Can you please send the minimum amount of changes to your database, the AL code and the steps needed to reproduce the issue.
Have you also changed OnBeforePostUpdateOrderLine not to be local?
Created below event inside my app, to write updated values to temp table with current data :
[EventSubscriber(ObjectType::Codeunit, 80, 'OnBeforePostUpdateOrderLine', '', false, false)]
local procedure SalesOnBeforePostUpdateOrderLine(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line");
var
LocalSalesLine: Record "Sales Line";
BEGIN
//this will use updated sales line while creating sales invoice lines with updated tax
//https://github.com/Microsoft/AL/issues/1885
IF AVAValidateCall.IsValidDocument(SalesHeader) THEN BEGIN
SalesLine.DELETEALL();
LocalSalesLine.RESET();
LocalSalesLine.SetRange("Document Type", SalesHeader."Document Type");
LocalSalesLine.SetRange("Document No.", SalesHeader."No.");
IF LocalSalesLine.FINDSET() THEN
repeat
SalesLine := LocalSalesLine;
SalesLine.Insert();
until LocalSalesLine.Next() = 0;
END;
END;
Steps:
- Create a Sales Order
- insert a single line & update Tax Group Code
- Post with Ship & invoice
- open posted document you will see below results

Click on navigate : open G/L entry and yo can see difference as this posted entry has tax in it

I'm somewhat confused as to what the actual problem is. From the screenshot you shown you're running on version 12.0. This version is for Business Central cloud release only. You have no way of modifying base application in the cloud.
Can you provide the following pieces of information:
- What is your runtime environment (Docker sandbox, online sandbox, On-Prem installer)
- What is your Business Central version
- What is you AL Language extension version
- C/AL code that introduces the custom event publisher
- AL code that subscribes to the custom event
Hello @StanislawStempin ,
Me and @chavansachin20 , working together against this particular issue.
please find the answers to your questions as below :
-
What is your runtime environment (Docker sandbox, online sandbox, On-Prem installer)
- Docker sandbox

- Docker sandbox
-
What is your Business Central version
- US Dynamics NAV 12.0 (21229)

- US Dynamics NAV 12.0 (21229)
-
What is you AL Language extension version
- 0.16.19969

- 0.16.19969
-
C/AL code that introduces the custom event publisher
- applied changes to CU 80 and set FunctionVisibility = External in C/SIDE for function -> OnBeforePostUpdateOrderLine as below

- applied changes to CU 80 and set FunctionVisibility = External in C/SIDE for function -> OnBeforePostUpdateOrderLine as below
-
AL code that subscribes to the custom event
- added below code inside "codeunit 70004822 "Ava SalesExtendCU80.al"

- added below code inside "codeunit 70004822 "Ava SalesExtendCU80.al"
hi @StanislawStempin , Are there any updates regarding this issue? Is there any more information required from our side?