RecordReference and Changecompany

Hello,

I want to read out data from various tables from different companys by RecordRefs and RecordIDs,

For example: for company “A” I want to read Item 1000, for company “B” I want to read item 1001. So I wrote the RecordIDs of item 1000 and 1001 in a new table with “Data Per Company” = No

In a new Codeunit I am reading every Company in a loop. When I am logged on in company “A”, I get an error by a RecRef.GET of company “B”. What’s wrong with my sourcecode? I am using Version 4 SP1 with Build 21666 with Native Database.

Table OutputRecords with “Data Per Company” = No

Primary Key: Field 1+2

1 Companyname Text 30
2 Transaction No. BigInteger
3 RecordID RecordID
4 Table No Integer

Sourcecode:

Company.RESET;
IF Company.FIND(’-’) THEN
REPEAT
OutputRecords.RESET;
OutputRecords.SETCURRENTKEY(Companyname,“Table No”);
OutputRecords.SETRANGE(Companyname,Company.Name);
IF OutputRecords.FIND(’-’) THEN
REPEAT
RecRef.OPEN(OutputRecords.“Table No”,FALSE,Company.Name);
RecRef.GET(OutputRecords.RecordID); <----CAUSE AN ERROR for foreign Companies

UNTIL OutputRecords.NEXT = 0;
UNTIL Company.NEXT = 0;

Try to define a RecID variable. This should help:

REPEAT
RecRef.OPEN(OutputRecords.“Table No”,FALSE,Company.Name);
RecID := OutputRecords.RecordID;
RecRef.GET(RecID);

UNTIL OutputRecords.NEXT = 0;

Hello,

the solution causes the same error message, that item 1001 does not exist.

If display the Company.Name and RecID by a Message, the shown values are correct, but RecRef.GET seems to refer to the wrong company.

Just for interest, did you ever try to use GETPOSITION AND SETPOSITION in this context ? It might help to see a little bit clearer.

Good idea. I never checked Get/-Setposition. Now I use a New Field Position in my Outputrecords-Table. In my loop Ii read this new field and use RecRef.SetPosition and it works fine. But I do not understand, why my RecRef.GET does not work.

Many thanks for quick help

Clemens Liedke