AL icon indicating copy to clipboard operation
AL copied to clipboard

Codeunit 80 - OnBeforePostUpdateOrderLine is not called while posting Sales transaction in Extension 2.0 build

Open chavansachin20 opened this issue 8 years ago • 23 comments

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;

chavansachin20 avatar Mar 29 '18 12:03 chavansachin20

@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.

image

chavansachin20 avatar Apr 02 '18 11:04 chavansachin20

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.

chavansachin20 avatar Apr 03 '18 05:04 chavansachin20

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

StanislawStempin avatar Apr 06 '18 14:04 StanislawStempin

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.

thpeder avatar Apr 12 '18 09:04 thpeder

@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)

chavansachin20 avatar Apr 17 '18 10:04 chavansachin20

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?

thpeder avatar Jun 13 '18 07:06 thpeder

Hello @thpeder ,

Below are details for version : Microsoft_Application_12.0.21229.0.app Microsoft_System_12.0.12928.0.app image

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

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

Only OnBeforePostUpdateOrderLine is not called from Subscription event.

chavansachin20 avatar Jun 18 '18 06:06 chavansachin20

@chavansachin20 If you scroll to the right, then there is a "Error Information" column, is there anything in that?

thpeder avatar Jun 19 '18 12:06 thpeder

@thpeder please see below screenshot : Error Information is blank.

image

chavansachin20 avatar Jun 26 '18 05:06 chavansachin20

@chavansachin20, Thanks for sending the screenshot. Could you try and regenerate the symbol file and download it to your project, like StanislawStempin recommended.

thpeder avatar Jun 26 '18 10:06 thpeder

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

chavansachin20 avatar Jul 05 '18 06:07 chavansachin20

@thpeder : I have followed below steps:

  1. applied changes to CU 80 and set FunctionVisibility = External in C/SIDE for OnBeforePostUpdateOrderLine.
  2. Reloaded symbols successfully.
  3. event subscription list (no error) image
  4. But while accessing it from VS code getting error as below image

please suggest further steps.

chavansachin20 avatar Jul 11 '18 08:07 chavansachin20

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: image

thpeder avatar Jul 11 '18 09:07 thpeder

@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 avatar Jul 11 '18 11:07 chavansachin20

@chavansachin20, Can you please send the minimum amount of changes to your database, the AL code and the steps needed to reproduce the issue.

thpeder avatar Jul 11 '18 12:07 thpeder

Have you also changed OnBeforePostUpdateOrderLine not to be local?

kalberes avatar Jul 12 '18 08:07 kalberes

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 image

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

chavansachin20 avatar Jul 12 '18 09:07 chavansachin20

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:

  1. What is your runtime environment (Docker sandbox, online sandbox, On-Prem installer)
  2. What is your Business Central version
  3. What is you AL Language extension version
  4. C/AL code that introduces the custom event publisher
  5. AL code that subscribes to the custom event

StanislawStempin avatar Aug 03 '18 12:08 StanislawStempin

Hello @StanislawStempin ,

Me and @chavansachin20 , working together against this particular issue.

please find the answers to your questions as below :

  1. What is your runtime environment (Docker sandbox, online sandbox, On-Prem installer)

    • Docker sandbox image
  2. What is your Business Central version

    • US Dynamics NAV 12.0 (21229) image
  3. What is you AL Language extension version

    • 0.16.19969 image
  4. 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 image
  5. AL code that subscribes to the custom event

    • added below code inside "codeunit 70004822 "Ava SalesExtendCU80.al" image

paragpardhi123 avatar Sep 26 '18 14:09 paragpardhi123

hi @StanislawStempin , Are there any updates regarding this issue? Is there any more information required from our side?

paragpardhi123 avatar Oct 03 '18 05:10 paragpardhi123