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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / DAX Beginners / ChangeCompany doesn’t work ...

ChangeCompany doesn’t work with Virtual Company

Christian Silva Profile Picture Christian Silva 707

Good day everyone,

This post has as subject virtual company, if you do not know what it is please read the link Virtual company accounts in Microsoft Dynamics AX [AX 2012].
Well, when you use the changeCompany() functionality and your environment has a configured virtual company it might cause a runtime error like this:

Image

This can be avoided by using changeCompany(table.company()) instead of changeCompany(table.dataAreaId).

static void _VirtualCompany(Args _args)
{
    DataArea dataArea;

    while select Id from dataArea
    {
        changeCompany(dataArea.company())
        {
            // Do something
        }
    }
}

The table.company() method get and sets the property that indicates a legal entity for the record. Which means, it will always returns the selectable company which can be properly used in a changeCompany() statement.

There’s also another way to avoid it by checking on DataArea table if the table DataAreaId is virtual or not. It works and people use it often but I still recommend to use table.company() for a clean code.

while select Id from dataArea
    {
        if (!xDataArea::find(dataArea.id).isVirtual)
        {
            changeCompany(dataArea.id)
            {    
                // Do something
            }
        }
    }


This was originally posted here.

Comments

*This post is locked for comments