web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Get table records via table number?

(0) ShareShare
ReportReport
Posted on by 70

Is it possible with any methods in AL to fetch all of the records from a table using the table number? I'd like to be able to do this in an API call that way if I'm trying to access/set a property with a lookup I can make the query to fetch all records related to the lookup number.

I have the same question (0)
  • Suggested answer
    Akshay_Panchal Profile Picture
    402 on at
    RE: Get table records via table number?

    Hi,

    Please check below reference link

    docs.microsoft.com/.../recordref-get-method

    Thanks

    Verify, If this answer helpful to you

  • Connor Hyde Profile Picture
    70 on at
    RE: Get table records via table number?

    Hi Akshay,

    Thanks for the response.

    Maybe I'm not implementing the method correctly, but that doesn't seem to be fetching a record. Whenever I try making my procedure return any type besides "Text", the API call returns "Resource not found for the segment {Codeunit_Method}".

    I tried returning a text of RecRef.Field(num).Name + RecRef.Field(num).Value but most of the time that just returns a field name with empty value.

  • Mohamed Amine Mahmoudi Profile Picture
    26,348 Super User 2025 Season 2 on at
    RE: Get table records via table number?

    hi you can use :

    var

       RecRef: RecordRef;

       MyFieldRef: FieldRef;

       RecID: RecordId;

    begin    

       RecRef.Open(TableNumber);  

       MyFieldRef := RecRef.Field(1);  

       MyFieldRef.Value := '30000';  

       if RecRef.Find('=') then begin  

         RecID := RecRef.RecordId;  

         RecRef.Get(RecID);  

       end;  

    end;

  • Connor Hyde Profile Picture
    70 on at
    RE: Get table records via table number?

    Hi Mohamed,

    Thank you for responding. This does work for returning a specific record with field #1 value = '30000', but is it possible to return ALL records on the table?

  • Verified answer
    Akshay_Panchal Profile Picture
    402 on at
    RE: Get table records via table number?

    Hii,

    see below, if you want to get all records from the given table id

    var

       RecRef: RecordRef;

       MyFieldRef: FieldRef;

       RecID: RecordId;

    begin    

       RecRef.Open(18);  

       if RecRef.Find('-') then repeat

         //your code here

       until RecRef.Next()=0;  

    end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,828

#2
Sumit Singh Profile Picture

Sumit Singh 2,617

#3
YUN ZHU Profile Picture

YUN ZHU 1,861 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans