Expression Code cannot be type-converted to a Option value


I am trying to create a report that uses 3 different tables. Since I don’t know of any other way I am using the get function like so.


ItemItem.GET(“Sales Price”.“Item No.”);

ItemDisc.GET(“Sales Price”.“Vendor No.”);


ItemItem=the item record

ItemDisc=sales line discount record

Im simply trying to return the values from all 3 tables in one body on the section. Im doing it this way for ease of export to excel.

The first line ItemItem works just fine, its the ItemDisc that gives the error and I dont know why.

My structure is:

Sales Price


Sales Line Discount

Thanks In advance.

Using the GET function requires that you use ALL primary key fields in the right order.

You cannot do a GET on the SalesLineDisc table with a code value as the first paramter of the GET function.

The primary key fields of this table are:
Type,Code,Sales Type,Sales Code,Starting Date,Currency Code,Variant Code,Unit of Measure Code,Minimum Quantity

On the other hand: Why are you trying a GET on the SalesLineDisc table with a Vendor No. ?

What you also need to consider is that you have multiple sales Line Discounts per item (depending on the customer, the date and so on).

Which one do you want to use?

I understand what you are saying about the keys/order, but Im confused as to why the first get function works with only the item no. IM not really clear what the statement is actually doing. I thought that with this statement

ItemDisc.GET(“Sales Price”.“Vendor No.”);

the Sales Line Discount table was crossreferencing the vendor no with the sales price vendor no. In my sections im returning the actual discount percentage for that vendor.

As for the discount to use, I was going to use the setrange function to define only discounts for our bulletin sales code. I hope that makes sense.


This is extremely confusing.

Usually the Sales line Discount table contains the discounts for sales, not purchases.

So there is no vendor no. (usually) in the sales Line Discount table.

Your first GET works as you are getting an ITEM which has a single field primary key only.

Can you please post all code for the saleslinediscount table ?


We are a distributor so the discounts in sales disounts are from vendor discounts, so basically that is the connection. The discounts are for sales, its basically an allowance from the vendor that we pass along to our customers on special occasions such as promotions.

I understand the first statement now, so I will look at the keys for the other table and go from there. As for the code. What I pasted is all I have unless you are referring to the properties of the text boxes? Cheers.

ItemItem.GET(“Sales Price”.“Item No.”);
ItemDisc.GET(“Sales Price”.“Type”);
ItemDisc.GET(“Sales Price”.“Code”);
ItemDisc.GET(“Sales Price”.“Sales Type”);
ItemDisc.GET(“Sales Price”.“Sales Code”);
ItemDisc.GET(“Sales Price”.“Starting Date”);
ItemDisc.GET(“Sales Price”.“Currency Code”);
ItemDisc.GET(“Sales Price”.“Varient Code”);
ItemDisc.GET(“Sales Price”.“Unit of Measure Code”);
ItemDisc.GET(“Sales Price”.“Minimum Quantity”);

That is the new code I tried and now Im getting an error that says “You have specified an unknown variable. Type”

Maybe Im not understanding what the code is doing but should the key names/order match the table for ItemDisc or Sales Price?

If its easier to address, my basic problem is that I cant figure out a way to have multiple tables in the same body of a report. If I could figure this out I would be fine and/or

If I knew how to use the printtoexcel function I wouldn’t need to worry about them being in separate headers.

Blitz: you need to know basic NAV - data-structure and practical use - and then comes development/extraction from NAV [8-)]

Thomas: think you have manouvered into seas with wast foggy areas…[;)]

Me? Going on holyday! [H]

Do you know how to find the primary keys of a table?

Where to start with your get code [:#]

Item table has a primary key of “No.” so that’s why
Item.Get(ItemNoValue) works

A Sales Header has two Document Type & No. so you would need to do
SalesHeader.Get(“Document Type”,“No.”); Where Doc type & No are filled with a value from the table your working on.

The Item Cross Reference for example has this as it’s primary key:
(Item No.,Variant Code,Unit of Measure,Cross-Reference Type,Cross-Reference Type No.,Cross-Reference No.)
ItemxRef.Get((Item No.,Variant Code,Unit of Measure,Cross-Reference Type,Cross-Reference Type No.,Cross-Reference No.)
where all those fields need a value.

Do you have the application Designers guide? There is a section on reports, that’s where you should start.

Does one of your tables contain values for the other tables you’re using . if so - then just use that one table and use get for the others.

*I d


you need to contact your Navision Partner, have one of their developers do this. If you want to get into Navision development to write your own reports, you need to get some training and learn the basics of Navision first.

@Anifinnur-I do know most of the basics of the data structure, I just dont know C/AL. Im not really trying to do anything really complicated so I thought I could get some quick help without upsetting the apple cart :slight_smile:

@David-I agree, and we have been waiting for training. Our partner is so busy trying to fix what they messed up so report writing is low on the list…right now I have to lose my code every time I close out of NAV, so im very frustrated. But business doesnt stop, so IM trying to do what I can.

@Savatage, its starting to become more clear to me. I will keep going…Thanks very much for the patience.

from here you can download the c/al programming guide (scroll down)

from here you can download the Application Designers Guide (scroll down) w1w1adg.pdf

They will be helpful

The thing is that this is not a programming issue. The issue here is that you need to have a clear understanding of the Navision application, how it works and the data structure. Even if you get this code to compile, it still wont work, because you don’t know which records are needed.

So even if your partner has promised you a week of Report designer training, it really wont help all that much. The report designer is pretty simple. The hard part is knowing what table means what and how they logically link together. I get pretty angry when I hear partners tell clients (normally at the sales stage) that they can learn the report designer in a week and then they can develop all their own reports. It simply is not true.

My job is fixing up Navision implementation that go wrong, so I do unfortunately see this quite a lot.

Dave I understand your frustration, it seems that I have posted under the wrong forum. I thought I was posting under the beginners sections. Would you mind moving it for me? As for the code itself I do know what records I need. I have read the documentation on the syntax for the get statement but Im not sure if its getting the record from the first Table or the table that is in the parenth…for example.

ItemDisc.Get(“Sales Price”.“Type”); is the record being retrieved for the item discount or the sales price table? Its basically a copy of an existing code on an existing report Im just changing the table.

Thanks Savatage for the documentation. I did have the one but not the other.

If you knew which record you need to get, then look at it, look at the primary key and all will become clear.