Importing value from table in report through code problem


I’m Dynamics NAV newbie and this is my first post here.

I’m using NAV for only around a month now, so, it’s quite possible I’m asking something stupid here.

I’m just an end user (so, no Application Builder or Solution Developer licence) , using NAV version 5.0 SP1.

I’m building a new report. When report is run, a user selects “Location Code” value from “Value Entry” table, in order to show items sold only from a specific location.

That filter (along with others) is shown on top of the report (as in many other built in reports) with this code in Report - OnPreReport() section:

VEFilter := "Value Entry".GETFILTERS;

What I wanted to do is to show actual location name instead of the code for that specific location. So, my actions were like this:

  • I wanted to get only “Location Code” number and not the whole filter name (e.g. something like ‘Location Code: 300’), so I added a global variable of text type named filt and this code:

filt := "Value Entry".GetFilter("Location Code");

in order to get only the number (e.g. 300). Is this a correct way to do this or should I parse string or something else?

  • next, I wanted to read from “Location” table (number 14 table) the name of the location corresponding to the location code I got through filtering, so I created a global variable named loc of type record and subtype Location table, and did this in Report - OnPreReport() section, too (nn is code typed global variable I used to store location code got in previous step, locname is a text type global variable used to store location name):

Evaluate(nn, filt);
loc.SetRange(loc.Code, nn);

locname := loc.Name + loc."Name 2";

and then I set the SourceExpr propertie of an appropriate text box to locname.

When I run the report, the text box is empty. It seems that no data is actually pulled from “Location” table. There is probably my mistake. I tried some stuff I have found on this and other forums, but I got nothing. It must be something really stupid I did.

Please, help if you can, I’d really appreciate it.

Thank you,

Bojan Milosevic

Oh, I got it! Finally!

I forgot to actually get a record from table after I filtered it. I put:

if loc.FindFirst then

locname := loc.Name + loc."Name 2";

and it works. Sorry for bothering you, but still, I would like to know if what I did is actually right way of doing this or there is something better? Thank you.

Best regards,

Bojan Milosevic

Hi Bojan,

Welcome to the Dynamics User Group!

As location is the primary key you could also use:

IF loc.GET( filt ) then

Not sure why you are using the EVALUATE function - I don’t think it’s required.

Hi Dave,

Thank you for welcome and for your answer.

Thank you for advise on GET function.

As for Evaluate function I used, you’re absolutely right. I completely overlooked that GetFilter function returns either string or code value as a result, so I wouldn’t really need that conversion. Thanks for pointing this out.

Oh, I’m so new to NAV, I make such obvious mistakes. Anyway, plenty of learning ahead. [:)]

Best regards,

Bojan Milosevic

Hi Bojan,

Glad to help [:D]

The application developer guide (in the Doc directory of the product DVD) has a lot of good advise/information and also David Studebaker’s book Programming Microsoft® Dynamics NAV is a great foundation.

Keep to the good work.