AL icon indicating copy to clipboard operation
AL copied to clipboard

SetLoadFields slow JTL response issue

Open CarlOhlsson opened this issue 5 years ago • 6 comments

1. Describe the bug I hope this is the correct place to report this issue, it is not an issue within the base app or any AL written code by Microsoft. Its more of an issue with how the underlying system handle SetLoadFields.

For about a week one of our customers get the following error message.

The field Bin Code of table Warehouse Shipment Line contains a value (SYRUM) that cannot be found in the related table (Bin).

However we have been using this code for a long time and there is no data issue to be found. I have tracked the issue and it seems to be caused by the SetLoadFields when a field not included in SetLoadFields is used in the table relation validation. A very special thing is that if you debug the code slowly the function that cause the issue works fine. But when you run it normal or debug the code very fast you get the error.

This made me think a bit. It has something to do with how SetLoadFields work where it seems the code continue to execute even if a JTL load is needed because the developer forgot a field in SetLoadFields. I have found nothing stating this is working as intended, previously the AL code execution was halted until the JTL load finished.

2. To Reproduce Steps to reproduce the behavior:

I created 2 functions to test the issue in the customer sandbox that let me reproduce the error message and the solution to it.

  1. Place these function in a new codeunit
  2. Create another function and simply get any warehouse shipment line and send it as parameter to any of my functions. Make sure to also include a valid BinCode for that shipment line.
  3. Run the code
    local procedure TestSetLoadFields_Working(WhseShptLine_P: Record "Warehouse Shipment Line"; BinCode: Code[20])
    var
        WhseShptLine: Record "Warehouse Shipment Line";
    begin
        WhseShptLine.SetLoadFields("Line No.", "Source Line No.", Quantity, "Source Document", "Source No.", "Bin Code", "Location Code");
        WhseShptLine.Get(WhseShptLine_P."No.", WhseShptLine_P."Line No.");
        WhseShptLine.Validate("Bin Code", BinCode);
    end;

    local procedure TestSetLoadFields_NotWorking(WhseShptLine_P: Record "Warehouse Shipment Line"; BinCode: Code[20])
    var
        WhseShptLine: Record "Warehouse Shipment Line";
    begin
        WhseShptLine.SetLoadFields("Line No.", "Source Line No.", Quantity, "Source Document", "Source No.", "Bin Code");
        WhseShptLine.Get(WhseShptLine_P."No.", WhseShptLine_P."Line No.");
        WhseShptLine.Validate("Bin Code", BinCode);
    end;

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.

3. Expected behavior With function TestSetLoadFields_NotWorking the Validation should pass without any errors.

4. Actual behavior When function TestSetLoadFields_NotWorking runs we get the error

The field Bin Code of table Warehouse Shipment Line contains a value (SYRUM) that cannot be found in the related table (Bin).

However when I run the TestSetLoadFields_Working everything works fine after adding "Location Code" to the SetLoadFields. 5. Versions:

  • AL Language: v7.4.502459
  • Visual Studio Code: 1.60.1
  • Business Central: 18.4.28601.29160
  • List of Visual Studio Code extensions that you have installed: AL Language

CarlOhlsson avatar Sep 15 '21 11:09 CarlOhlsson

I think this was actually fixed in version 19, @CarlOhlsson would you be able to test out the code on a 19 preview docker instance?

PhDuck avatar Sep 17 '21 18:09 PhDuck

@PhDuck

I can test it but a bit short on time this week. Will hit back here when tested.

Closed by misstake, please open up again.

CarlOhlsson avatar Sep 21 '21 16:09 CarlOhlsson

Will the fix be backported to 18.x?

dzzzb avatar Sep 22 '21 13:09 dzzzb

Will the fix be backported to 18.x?

Depends, if it is what we already fixed, it is rather likely that we could backport it since the change is small. If it is some new large bug that will require a large change to fix, then most likely not.

PhDuck avatar Sep 23 '21 12:09 PhDuck

@CarlOhlsson Have you found any time to reproduce this on 19?

I'm not going to prioritize this before I know if it reproduces on 19.

PhDuck avatar Oct 04 '21 15:10 PhDuck

@PhDuck Dont have an exact copy of my scenario in a 19 environment but I set up something similar with another record and it seems to be fixed. Tested on the just released saas version.

CarlOhlsson avatar Oct 04 '21 20:10 CarlOhlsson