Error: RecordReference and Changecompany

Clemens_LiedkeClemens_Liedke Member Posts: 4
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;

Comments

  • krikikriki Member, Moderator Posts: 9,118
    Try something like this:

    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);
            
            // now it depends on what you have in "OutputRecords.RecordID".
            //   So you have to use one of these:(RECORDID,SETPOSITION OR fill up the keyfields 1 by 1)
            RecRef.RECORDID(OutputRecords.RecordID); 
            RecRef.SETPOSITION(OutputRecords.RecordID);
    
            RecRef.FIND('='); // get the record by using the values in the primary-key fields.
    
          UNTIL OutputRecords.NEXT = 0;
      UNTIL Company.NEXT = 0;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.