CrossCompany and ChangeCompany in AX

Today I will demonstrate you that how to retrieve data from multiple companies or all companies by using CrossCompany and ChangeCompany in AX.

CrossCompany:- By using this keyword we can retrieve data from multiple companies or from all companies.
          
                 Example:-
                    CustTable cust;
                    Container con;
                    con=["ceu","Dat","cee"];
                    Select crosscompany:con cust;
                    print cust.accountnum;
                    pause;


                 Example:-
                    CustTable cust;
                    Select crosscompany cust;
                    print cust.accountnum;
                    pause;


ChangeCompany:- By using this keyword we can change company any time and retrieve data from specific companies.

                Example:-
                    CustTable cust;
                    Select *from cust;
                    print cust.accountnum;
                    changecompany("Cee")
                    {
                     cust=null
                    Select *from cust;
                    print cust.accountnum;
                     }
                    changecompany("Ceeu")
                    {
                     cust=null
                    Select *from cust;
                    print cust.accountnum;
                     }
                    pause;

Comments