Open SShadowS opened 5 years ago
Code works fine in BC 13, so bug introduced in BC14+
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.
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.
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:
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:
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