microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
728 stars 241 forks source link

Funny Page.RunModal compile error #5209

Open SShadowS opened 5 years ago

SShadowS commented 5 years ago

Page.RunModal is defined as followed: [Action := ] Page.RunModal(Number: Integer, Record: Record, FieldNo: Integer)

If you set FieldNo by using the value in a field on a table, it will work out of the box, UNLESS the field on the table contains the text "FieldId". Then it will instead insert the FieldId of the table field, and not the value of the field.

Create a field on a table like this:

field(25; MyAwesomeFieldId; Integer)
{
    DataClassification = CustomerContent;
}

Insert the value 999 in the field.

And the use it in a RunModal like this: Page.RunModal(27, Vendor, TestTable.MyAwesomeFieldId);

This will cast an error, saying field 25 don't exist on table Vendor.

So it doesn't pass though the value 999 from the table, instead it passes the FieldId of MyAwesomeField.

As long as the field ends on FieldId this bug will happen.

If I instead do this:

var
 Int: Integer;
begin
    int := TestTable.MyAwesomeFieldId;
    Page.RunModal(27, Vendor, Int);
end;

Then it works, so it is RunModal which is bugged.

Example code here: FieldNoBug.zip

Expected behavior Passing 999 and not the FieldID of the field containing 999.

Versions: Name: AL Language Id: ms-dynamics-smb.al Description: AL development tools for Dynamics 365 Business Central Version: 3.0.152816 Publisher: Microsoft

Business Central: Fresh Docker mcr.microsoft.com/businesscentral/onprem:cu2-dk 14.0.34251.0

SShadowS commented 5 years ago

Code works fine in BC 13, so bug introduced in BC14+

SShadowS commented 5 years ago

Correction

It is no related to the field name, it simply just uses the field no of the field instead of the value.

So might be an undocumented change or newly introduced bug which breaks it. Documentation clealy states it requests an integer.

FieldNo  Type: Integer Use this optional parameter to select a specific field on which focus will be put.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/page/page-runmodal-integer-table-integer-method

dzzzb commented 3 years ago

I think under the hood this function works as if it has overloads for (a) FieldNo as an actual Integer and (b) passing a SomeTable.SomeField 'reference' which then gets converted to the ID of said field.

That then means that if you want to use the value of an Integer field as the FieldNo - not its ID - then you need to work around this by putting it in an Integer variable first, as you saw, as otherwise there's no way to disambiguate, and the 'overload' taking 'field ref' wins.