GETing a record/field from another table

This suppose to be the easy part of developing reports but I’m still having problems. How do I retrieve a field/record from another table without adding it as a DataItem? For example, name of customer (from tbl. Customer) by using the cutomer nummber (from another tbl.). Thanks in advance. Tariq

Hi, Define a global variable rcCustomer as Rec Customer. Then try this CODE IF NOT rcCustomer.GET(Customercode) THEN rcCustomer.INIT;

Hi Wiesekopsieker, Thanks for your reply. As far as I understood it, this code would store the record for a specific customer number in rcCustomer. Now to get the name of the customer, should I define another text variable (CustName) & use the following code, CustName := rcCustomer.Name; or Should I define SourceExpression : rcCustomer.Name for the text box ? Apparently, non of these work ! Help please … Tariq

Tarik, You can either have Customer.Name or CustName as Source Expression, Both will work. Try the following snippet : IF Customer.GET(CustNo) THEN CustName := Customer.Name ELSE ERROR(‘Cannot find Customer No. %1’, CustNo); tarek_demiati@ureach.com

Hi again, I just tried another methode which might not be optimal one but works fine. Which is defining two global record variables & one text variable. Then apply the following codes, RecVar1.SETRANGE(CustomerNo,ThisTbl.CustomerNo); IF NOT RecVar2.GET(ThisTbl.CustomerNo) THEN RecVar2.INIT; CustName := Recvar2.Name; Thanks a lot for your help. Please post a reply if you can think of a better way of doing the same. Regards, Tariq

Thanks Tarek, You suggested a rather simple methode then the one I’m using. Regards, Tariq

quote:


RecVar1.SETRANGE(CustomerNo,ThisTbl.CustomerNo); IF NOT RecVar2.GET(ThisTbl.CustomerNo) THEN RecVar2.INIT; CustName := Recvar2.Name;


I have two comments: 1) It is not necessary to do a

RecVar1.SETRANGE(CustomerNo,ThisTbl.CustomerNo);

What for? You neve use RecVar1. 2) Why do you store the customer name in a temporary variable? You have the whole Customer Record stored in RecVar2. You can use RecVar2.Name directly in your form/report as source expression. There’s no need to store it temporarily. ------- With best regards from Switzerland Marcus Fabian

tariq fabian is right look at your Sales Documents for examples. They use page loop and copy loop referencing the table fields inthe section like this in the source expression “Sales Header”.“No.” for the previous DataItem or SalesHeader.“No.” for a variable Hope this makes things clearer for you! David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk

Fabian, thanks a lot for your comments. You are right. I just looked up in some other reports & found a solution. And David, thanks to you as well for further clearification. Kind regards, Tariq

What about using flowfields as a lookup field in a table. You can refer to different tables.

One minor point about using a record variable pointing to the Customer table. Record variables are often (usually) best declared as LOCAL variables not global variables. A local variable is a variable which is used only by one trigger. If you want to pass it to another trigger, pass it as type VAR. ------- Tim Horrigan horrigan@aol.com

quote:


Originally posted by horrigan: One minor point about using a record variable pointing to the Customer table. Record variables are often (usually) best declared as LOCAL variables not global variables. A local variable is a variable which is used only by one trigger. If you want to pass it to another trigger, pass it as type VAR. ------- Tim Horrigan horrigan@aol.com


Quite Right Tim very good practice. tariq Use a local variable within a function for a one time use to get a record to pass back or to return a value, in the report you need a Global variable as this needs to be seen and used by several of the lower DataItems David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk

Hi again, Now I’m facing another problem. That is, when I use a Code field to GET a record from another table then a run time error occurs “Can’t convert a Code data type to an Option”. Even converting Code to Text before GET doesn’t help. Any ideas ?? Thanks in advance. Regards, Tariq

Example: If you want to read a sales line where the primary key is defined as Document Type : Option Document Number: Code 20 You cannot get an invoice as:

salesline.get(DocNo) 

You must instead read it as

salesline.get(DocType,DocNo) 

------- With best regards from Switzerland Marcus Fabian

Tariq, please do another posting on your new topic. As this will let other developers find your topic easier from the list. Thanks, Soren Nielsen, moderator Integration/Developer NOLUG