Hey folks,
this piece of code seems quite trivial, but I am stuck with it.
I would have expected to get the
Document Type in the first Message and the
Sell-to Customer No. in the two latter ones, but NAV shows only the Doc Types value. Am I missing something? Obviously, but what? I first ran into this in Business Central, then tried to narrow it down in NAV2018.
Why is there no value for the Customer No?
SalesHeader.FINDFIRST;
RecId := SalesHeader.RECORDID;
RecRef := RecId.GETRECORD;
FieldRef := RecRef.Field(1);
Message(Format(FieldRef));
FieldRef2 := RecRef.Field(2);
Message(Format(FieldRef2));
// CU 701 DataTypeManagement
DataTypeManagement.FindFieldByName(RecRef, FieldRef2, 'Sell-to Customer No.');
Message(Format(FieldRef2));
Answers
Instead of using 'RecRef := RecId.GETRECORD' use 'RecRef.GET(RecID)'.
From the help page for GETRECORD it says:
Remarks
No data is read from the database when you run this function and therefore, no other fields in the record are set. Furthermore, no filters are set on the record.