Share via


Change Company Design Pattern

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

A change to the design pattern of a large company is often the result of it being split into several legal entities. The Microsoft Dynamics AX development environment supports this by using the changeCompany function in X++.

The changeCompany statement is used to alter the database settings to another (separate) company. The syntax of the statement is:

changeCompany ( Expression ) Statement

Expression is a string that defines which company is to be used. The statement is executed on the new company. The following example shows how to use this statement.

static void main()
{
    CustTable custTable;
    ;
 
    // Assume that you are running in company 'aaa'.
    changeCompany('bbb') // Default company is now 'bbb'.
    {
        custTable = null;
        while select custTable
        {
            // custTable is now selected in company 'bbb'.
        }
    }
    // Default company is again set back to 'aaa'.
 
    changeCompany('ccc') // Default company is now 'ccc'.
    {
    
        // Clear custTable to let the select work
        // on the new default company.
        custTable = null;
    
 
        while select custTable
        {
            // custTable is now selected in company 'ccc'.
        }
    }
    // Default company is again 'aaa'.
}

changeCompany Interactions with crossCompany

The changeCompany keyword is useful in scenarios where the crossCompany keyword is used. For more information, see Cross-Company Data Modification Using X++.

See also

Microsoft Dynamics AX Design Patterns

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.