Writing a report

I’m writing a report on a table that doesn’t exist in the default tables. Basically, there are values that are inputted in a form and then a report has to be generated.

Most of the values I want to generate are in the table, so it’s not that complicated, but I’m struggling to include a value from another table, the Item table.

Basically, there’s a way to “setrange” both tables (through the field “No.”), but how can I “say”, in code, that I want to get that value from the field “Material” of the Item table. What do I write after this (on the OnAfterGetRecord trigger)?

RecItem.SETRANGE(“No.”, “No. Equipamento”);


RecItem.SETRANGE(“No.”, “No. Equipamento”);



What exactly you want to do with RecItem.“Material” field?

You can simply use RecItem.“Material” field in begin end as you have already got the item record…


RecItem.SETRANGE(“No.”, “No. Equipamento”);




I already tried that, but the message came empty…

Then check whether you have value in Item table for that record.

Before that check whether you have any value in “No. Equipamento” or not

Message(’%1’,“No. Equipamento”);


RecItem.SETRANGE(“No.”, “No. Equipamento”);




So, just to summarize … you have a custom table that includes the field "No. Equipamento” and this field is related to the “No.” field in the Item table. Now you’re writing a report on the custom table and you need to include some data from the Item table.

In your report, in the OnAfterGetRecord trigger of your custom table, you’ll need to retrieve the Item record that’s related to the value in “No. Equipamento”. Once you have the right Item record in current memory, you have access to all of the fields in the table and you can pretty much do whatever you want with it.

There are a couple of ways to go about finding the matching Item record. You can use the FILTER/FIND method like you’ve already been discussing, or you can use the GET method. In this case, I’d prefer the GET method because it’s less complicated to code, it returns the Item record far more quickly (the “No.” field is the primary key for the Item record), and you don’t have to write any special error-handling code if you don’t want to. You would simply type one single command:

Item.GET(“No. Equipamento”);

and that’s it. If you really want to get fancy, you can add code to trap for possible errors, like the case where “No. Equipamento” is blank…

if “No. Equipamento” <> ‘’ then

Item.GET(“No. Equipamento”);

or the case where you have an invalid value in "No. Equipamento”…

if not Item.GET(“No. Equipamento”) then

… raise an error, or

… call Item.INIT to blank the record and continue on

In either case, it’s definitely quicker, and much easier than trying to remember to return the Item record to its previous condition (filters, current record, etc.)

Once you have the right Item record in current memory, you can display any of the field values on the report by creating text boxes and using Item.“Description” or any other Item field as the source expression.

That should solve your problem.

Oh, and one other observation, if you don’t mind? I haven’t been at this for too terribly long, but I have come to understand that the community frowns most strenuously on the use of Hungarian naming conventions or anything that remotely resembles it. So, rather than naming your variable RecItem, just call it Item. There’s a document out there that covers nothing but naming conventions. It’s a great resource. And if you get stuck, just search the standard Navision code to see how the original developers name objects. You will see variations here too, but you’ll at least be able to see what the standard looks like.

I hope that helps. Sorry that it’s so long.

I do have values for the equipment number.

One odd thing: the value I’m looking for (“material”) has a down arrow next to its place at the item form. I noticed that the value of “material” is in the “description” field of another item, more specifically another type of item.

Is it possible that instead of getting the value of “material”, I can get the value of that “description” field? Is it the best way? But how can I make a relation in the same table?

@George Love

My problem stands. I need to make that value appear on the report, and I haven’t been able to.

About the naming conventions, I hadn’t realized it yet, I’ll try to correct that in the future. Thanks for the warning…

Check what kind field is equipment number in table FieldClass property(Normal or Flowfield)?

IF flow field,CalcFormula property will tell you how it is calculating

OK, we’re making progress. From your description, it sounds like the Material field on the Item record is defined as a flowfield rather than a normal field. In order to get these fields to properly display their values in a report, it is often necessary to tell Navision to update the value of the field before displaying it on the report. This is done with the CALCFIELDS command. In your case, the code would look something like this …

Item.GET(“No. Equipamento”);

Then, to get that value to display on the report, create a textbox and assign Item.Material as the source expression.

If that doesn’t produce the result you’re looking for, you may need to take a look at the field definition for Item.Material. It may not be defined in a way that will return the data you’re looking for. Or, if the down arrow you mention is actually a downward-pointing triangle, then the field is more likely defined as an option rather than a flowfield, and we have a different problem entirely to address.

Try the Calcfields bit and let us know how it turns out.

I used the CALCFIELDS and it worked fine. Thanks for the tip!

My report is coming along…

Now I need to know another thing:

In the form (the custom form for the custom table I mentioned before), I have a print button. I want to be able to push that button and print the report based on the lines added in that form.

Should I just set some filters?

Setting filters is probably your best approach to running the report against several of the entries in your list form.

Before getting into detail about printing the report, another request was made to me:

Each report shows information about an equipment that’s supposed to be manufactured. The equipment is manufactured so that a product is also manufactured using that equipment (t he report shows that too).

The problem is that the report works well if each equipment (No.) is related only to one product (Item.No.). What if each equipment is going to be used to produce two or more products.

How can I consider that in my report? How can I print information for two or more products if that’s the case. My boss told me to “find out and solve the problem”, so here I am, seeking help from you…

I found out what I needed to do. I needed to create a new DataItem…

Ok, so now I am trying to print the report. The form is working well, and the print button is added. But I don’t know how to print the report with the filters. I want to print the report with the lines that are filled in the form. Can you tell me how?

I realized that in order to get the result I want, I need to filter both dataitems, the question is, how do I do it?