AdvancedMicrosoft Dynamics 365 Business CentralAL Development / Tables

Business Central Item Table (27), Table 6507 and Temporary Tables in AL

Question
business central item table

Also searched as

  • business central table 6507
  • business central temporary table
  • business central item table number 27
  • al temporary record variable business central

Short answer

The Business Central Item table is table 27. Table 6507 is Item Entry Relation, a link table used with item tracking, not the Tracking Specification, which is table 336 and is normally used as a temporary table. A temporary table in AL is an in-memory copy of a table structure that never writes to the database, declared with the temporary keyword or the TableType property.

Applies to: Dynamics 365 Business Central online and on-premises, current and recent AL versions. Table numbers in the base app are stable, but confirm in your own environment with the Table Information page or the symbols.

How to work with these tables in AL

  1. 1Find the table in your environment: search for Table Information or open the base app symbols in VS Code and look up the object by number or name.
  2. 2Read from the Item table (27) by record: declare Item: Record Item, set filters on No., Blocked or Inventory Posting Group, then call FindSet and loop.
  3. 3For stock quantities, do not read a stored field: Inventory is a FlowField, so call CalcFields(Inventory) before using it.
  4. 4To inspect item tracking links, look at Item Entry Relation (6507), which connects a source document line to the item ledger entries created for it, plus Item Ledger Entry (32) for the entries themselves.
  5. 5When you need a working set that must not hit the database, declare a temporary record: TempItem: Record Item temporary;.
  6. 6Fill it with Insert, loop it, and bind it to a page by setting SourceTableTemporary = true on the page.
  7. 7Remember temporary data disappears when the variable goes out of scope. Copy results to real tables only through the proper posting routines.
  8. 8Test with several companies and data volumes, since filters and FlowFields behave differently with larger data.

The Item table (27) in practice

The Item table holds the item master: No., Description, Base Unit of Measure, Inventory Posting Group, Costing Method, Unit Cost, Unit Price, Replenishment System, Reordering Policy and many more. It is linked to Item Ledger Entry (32) and Value Entry (5802) for quantity and cost, and to Item Unit of Measure, Item Variant and Item Substitution for variations.

Quantities are mostly FlowFields calculated from item ledger entries, such as Inventory, Net Change, Qty. on Sales Order and Qty. on Purch. Order. They return zero until CalcFields runs in code, which is a frequent source of why does my item show no stock bugs.

Do not modify posted data. Changing Item fields such as Costing Method after entries exist is blocked or restricted, because the cost history depends on it. Use the standard pages and posting routines rather than direct Modify calls on ledger tables.

var
    Item: Record Item;
begin
    Item.SetRange(Blocked, false);
    if Item.FindSet() then
        repeat
            Item.CalcFields(Inventory);
            if Item.Inventory < 0 then
                Message('Negative stock on %1', Item."No.");
        until Item.Next() = 0;
end;

What table 6507 is, and the tracking tables around it

People often search for table 6507 expecting the tracking spec. In the base app, 6507 is Item Entry Relation, which stores which item ledger entries belong to which source document line, for example a posted purchase receipt line and the lot or serial entries created from it. Its sibling, Value Entry Relation, links value entries.

Item tracking while a document is open uses Reservation Entry (337) for stored lines, and Tracking Specification (336), which the item tracking lines page uses as a temporary table. Lot No. Information and Serial No. Information (6505 and 6504 in the base app) hold master data for tracked numbers.

Table numbers are a convenience, not a contract. If you build an extension, reference tables by name (Record "Item Entry Relation") rather than by number, so symbols keep the dependency readable and checked at compile time.

How temporary tables work in AL

A temporary record has the same fields and keys as a real table but lives only in memory for the lifetime of the variable. Insert, Modify, Delete and FindSet all work, but nothing is written to the database and no locking or database transaction applies. Table triggers run only if you ask, as with Insert(true).

Typical uses are building a result set for a page or report, aggregating data for an API, buffering import lines for validation, and holding the Tracking Specification lines during an item tracking dialog. Pages with SourceTableTemporary = true or tables with TableType = Temporary behave the same way.

A temporary table that receives a rec copy of the real table needs a deliberate loop, since assignment of a temporary variable to a real record copies field values only for the single current record.

var
    TempItem: Record Item temporary;
    Item: Record Item;
begin
    Item.SetRange("Inventory Posting Group", 'RESALE');
    if Item.FindSet() then
        repeat
            TempItem := Item;
            TempItem.Insert();
        until Item.Next() = 0;
    // TempItem now holds an in-memory copy, nothing written to the DB
end;

Performance and troubleshooting

Use SetLoadFields before FindSet on Item when you need only a few fields, and use SetCurrentKey with matching filters so the SQL engine uses an index. Wide tables like Item are expensive to read in full inside loops.

A common mistake is calling Rec.Insert on a temporary variable with the primary key unset, which raises a duplicate or empty key error. Another is expecting a temporary record to see changes made later in the database. Remember too that on a page with a temporary source table, the standard actions work on the in-memory copy.

Try it here, free

Business Central AL Extension Skeleton Generator

Open full tool

Fill in publisher, prefix and ID range to get app.json, a table extension, a page extension, an event subscriber codeunit and a permission set.

Common pitfalls

  • !Reading Inventory or other FlowFields without CalcFields and concluding the item has no stock.
  • !Assuming table 6507 is the tracking specification, when it is Item Entry Relation and the tracking spec is table 336.
  • !Using table numbers instead of names in extension code, reducing readability and symbol checking.
  • !Expecting a temporary record to persist or to be visible to other sessions after the variable goes out of scope.
  • !Modifying ledger or relation tables directly instead of using standard posting routines.

How an ERP-grounded AI assistant handles this

For Business Central, a private AI layer can answer questions like which items have negative inventory or which lot numbers came in on a posted receipt by querying the Item, Item Ledger Entry and Item Entry Relation data read-only through the API or a replica, showing the query it used. For AL development work, it can also draft the CalcFields and SetLoadFields loops, which a developer reviews before use.

Frequently asked questions

What is the Business Central item table number?

The Item table is table 27 in the base application. Related tables include Item Ledger Entry (32), Value Entry (5802), Item Unit of Measure (5404) and Item Variant (5401). Confirm the numbers in your environment through the Table Information page or the symbols in VS Code.

What is table 6507 in Business Central?

In the base application, table 6507 is Item Entry Relation, which links a source document line to the item ledger entries created from it. Tracking Specification is table 336 and Reservation Entry is table 337. Verify in your own version.

How do I create a temporary table in AL?

Declare a record variable with the temporary keyword, for example TempItem: Record Item temporary, or set the TableType property of your own table to Temporary. It lives in memory only and is discarded when the variable goes out of scope.

Why does Item.Inventory show zero in my code?

Inventory is a FlowField, so it is calculated only when you call CalcFields(Inventory) on the record, or when a page calculates it for display. Without that call, the value stays zero.

Related

How-to

CalcFormula in Business Central: FlowFields With Sum, Count, Exist and Lookup

CalcFormula defines how a FlowField is calculated from other tables. A FlowField is not stored. It is computed on demand using Sum, Average, Min, Max, Count, Exist or Lookup over a source table filtered by conditions. Read it with CalcFields or SetAutoCalcFields, and keep it fast with a key that supports the filter and sum.

How-to

Calling and extending the Business Central API v2.0

The Business Central API v2.0 is a REST/OData endpoint at api.businesscentral.dynamics.com/v2.0/{tenant}/{environment}/api/v2.0, authenticated with Azure AD OAuth 2.0. It exposes standard entities like customers and items, and lets you publish your own with an AL API page.

How-to

Business Central Integration Events: How to Publish and Subscribe in AL

An integration event is a procedure marked with the IntegrationEvent attribute that has an empty body. Code elsewhere subscribes to it with the EventSubscriber attribute, so extensions can change standard behavior without modifying base objects. You publish with IntegrationEvent, subscribe with EventSubscriber, and pass var parameters when the subscriber needs to alter data.

How-to

Creating and selecting custom report layouts in Business Central

Business Central reports can render through a Word layout (simple, single-level documents like invoices) or an RDLC layout (complex, multi-level, grouped reports). Custom layouts are uploaded and assigned per report through the Report Layout Selection page, or shipped inside an AL extension with the rendering(...) property.

Error fix

Fixing "You do not have the following permissions on TableData (table): (permission)" in Business Central AL

This runtime error means the current user's assigned permission sets do not grant the required Insert, Modify, Delete, Read, or Execute right on that specific table. It is most common right after installing or updating a custom AL extension, because Business Central checks object-level permissions even for tables an extension owns.

Error fix

Fixing "Cannot create a record in (table). The record already exists" in D365 F&SCM data entity imports

This is the standard kernel duplicate-key exception, thrown when the Data Management Framework tries to insert a staging row into a target table whose unique or alternate key already matches an existing record. It almost always means the entity's insert-vs-update logic did not recognize the target row as an update, not that you have a true accidental duplicate in your source file.

AI for ERP

AI for Business Central Inventory: Ask About Stock, Bins, Costing and Variances

AI for Business Central inventory: query item ledger, bins, reorder points and costing, find stock mismatches, and plan counts with audited, read-only access.

AI for ERP

AI for Dynamics 365 Business Central, on-premises or SaaS, beyond Copilot

AI for Business Central beyond Copilot: grounded question answering over BC's data via OData and APIs, for on-premises and SaaS tenants alike.

Stuck on Microsoft Dynamics 365 Business Central?

Talk to engineers who work inside Microsoft Dynamics 365 Business Central every week, and who build private AI that answers these questions from your own ERP data.

Keep exploring

Free tools

ERP fixes and how-tos

AI on your ERP

Integrations

Comparisons

Software