Expression Code cannot be type-converted to a Option value

Hi all,

In a report with data item Sales Line I wrote the following code in the OnAfterGetRecord:

IF gRecPurchaseLine.GET(“Sales Line”.“Purchase Order No.”,“Sales Line”.“Purch. Order Line No.”) THEN
gCodVendorOrderNo := gRecPurchaseLine.fCodVendorOrderNo;

Variables:
gRecPurchaseLine, Record (Purchase Line)
gCodVendorOrderNo, Code

The fCodVendorOrderNo in table Purchase Line is a custom field of type Code.

When running the report I get the error message ‘The expression Code cannot be type-converted to a Option value’.

I do not understand. What am I doing wrong?

When you are using the Get function you need to use all the fields in the primary key of the table you are trying to get the record from.

You are missing Document Type at the start of the get which is a Option String.

Need to remember that the purchase line table can contain Quotes, Orders, Invoices etc etc.

So your GET must read:

IF gRecPurchaseLine.GET(gRecPurchaseLine.“Document Type”::Order,“Sales Line”.“Purchase Order No.”,“Sales Line”.“Purch. Order Line No.”) THEN

Thank you Littleoaks and Thomas. Learning every day!

Nice to get feedback.

Glad it works now.
I mark the issue as solved.