Skip to main content

Notifications

Announcements

No record found.

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.

  • 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;

  • 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?

  • Mohamed Amine Mahmoudi Profile Picture
    22,998 Super User 2025 Season 1 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 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.

  • 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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 365 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 242

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 226 Most Valuable Professional

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans