Skip to main content

Notifications

Business Central forum
Answered

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

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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans