Skip to main content

Notifications

Announcements

No record found.

Business Central forum

"You must select a company before you can access the table"

(0) ShareShare
ReportReport
Posted on by

I am trying to install an extension locally with the PS commands publish-navapp and install-navapp and get the error "You must select a company before you can access the item table". I am simply trying to add some items in a subtype=install codeunit. Has anyone else experienced this error? I have searched for an answer and cannot find one.

Thanks.

Categories:
  • Verified answer
    RE: "You must select a company before you can access the table"

    The error you are receiving usually suggests that you are attempting to access a table whose data is considered ‘Per-Company’ outside of a company context.

    The default value for all tables in the AL syntax is for the data to be ‘Per-Company’ but can be set explicitly with the ‘DataPerCompany’ property.

     

    Code similar to this:

    table 50100 MyPerDatabaseTable

    {

        DataPerCompany = false; // Makes the table per-database

        // <Table fields, code, etc.>

    }

     

    From your description, I might assume that the problematic code is being executed from within the ‘OnInstallAppPerDatabase’ trigger in your install codeunit. When this trigger is run there is no company context, so any attempt to access a per-company table from there would result in this error.

    If you need to perform ‘install’ related tasks for you per-company tables, then they should be done in the ‘OnInstallAppPerCompany’ trigger instead.

     

    See this reading:

    https://docs.microsoft.com/en-us/dynamics-nav/developer/devenv-extension-install-code

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans