AX 2009 feature: cross company support

In X++, there is a new keyword crossCompany you can use in a select statement. Additionally, you can add a container with all the company ID’s you want to include in your select statement.
So, your select statement could look like that:

while select salestable crossCompany : [dmo, cos]
{
... do something ...
}

Now, that’s really a huge step forward from the good old changeCompany function.

Ledger Settlement is very slow

This problem can be done when you do a migration of data of Ax. Why is it slow ? I don’t know, but you can increase the speed by modifying these piece of code :

Class CustVendPaymNote.buildPaymNote()

[...]
    CustVendTransOpen   custVendTransOpenSelect;
    CustVendTrans       custVentTransSelect;
    ;
[...]

// BEGIN
//    while select crossCompany RecId from specTrans
//        where specTrans.SpecCompany == _specCompany
//           && specTrans.SpecTableId == _specTableId
//           && specTrans.SpecRecId   == _specRecId
//        join RecId from custVendTransOpen
//            where custVendTransOpen.DataAreaId == specTrans.RefCompany
//               && custVendTransOpen.TableId == specTrans.RefTableId
//               && custVendTransOpen.RecId   == specTrans.RefRecId
//        join TransDate, DocumentNum, Invoice, PaymId, Voucher from custVentTrans
//            where custVentTrans.RecId == custVendTransOpen.RefRecId

    while select crossCompany RecId from specTrans
        index   hint SpecIdx
        where specTrans.SpecCompany                     == _specCompany
           && specTrans.SpecTableId                     == _specTableId
           && specTrans.SpecRecId                       == _specRecId
        join RecId from custVendTransOpenSelect
            where custVendTransOpenSelect.DataAreaId    == specTrans.RefCompany
            && custVendTransOpenSelect.TableId          == specTrans.RefTableId
            && custVendTransOpenSelect.RecId            == specTrans.RefRecId
        exists join TransDate, DocumentNum, Invoice, PaymId, Voucher
            from    custVentTransSelect
            where   custVentTransSelect.RecId           == custVendTransOpenSelect.RefRecId
    {
        select  firstonly custVendTransOpen
        where   custVendTransOpen.TableId   == specTrans.RefTableId
        &&      custVendTransOpen.RecId     == specTrans.RefRecId;

        select  firstonly custVendTrans
        index   RecId
        where   custVendTrans.RecId == custVendTransOpen.RefRecId;
// END

Class LedgerJournalTransUpdateVend.checkSettleVoucher()

...
    VendTrans               vendTransSelect;
    VendTable               vendTransVendorSelect;
    ;
...

// BEGIN
//        while select crossCompany specTrans
//            where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
//                specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
//                specTrans.SpecRecId == _ledgerJournalTrans.RecId
//            join vendTransOpen
//                where specTrans.RefCompany == vendTransOpen.DataAreaId &&
//                    specTrans.RefTableId == vendTransOpen.TableId &&
//                    specTrans.RefRecId == vendTransOpen.RecId
//            join vendTrans
//                where vendTransOpen.RefRecId == vendTrans.RecId
//            join vendTransVendor
//                where vendTrans.AccountNum == vendTransVendor.AccountNum
        while select crossCompany specTrans
            where   specTrans.SpecCompany   == _ledgerJournalTrans.company()
            &&      specTrans.SpecTableId   == _ledgerJournalTrans.TableId
            &&      specTrans.SpecRecId     == _ledgerJournalTrans.RecId
        join RefRecId
            from    vendTransOpen
            where   vendTransOpen.DataAreaId    == specTrans.RefCompany
            &&      vendTransOpen.TableId       == specTrans.RefTableId
            &&      vendTransOpen.RecId         == specTrans.RefRecId
        exists join vendTransSelect
            where   vendTransSelect.RecId       == vendTransOpen.RefRecId
        exists join vendTransVendorSelect
            where   vendTransVendorSelect.AccountNum    == vendTrans.AccountNum
// END
        {
// BEGIN
            vendTrans       = VendTrans::find(vendTransOpen.RefRecId);
            vendTransVendor = VendTable::find(vendTrans.AccountNum);
// END

Last class : LedgerJournalTransUpdateCust.checkSettleVoucher

...
    CustTable               CustTransCustomerSelect;
    CustTrans               custTransSelect;
    ;
...

// BEGIN
//        while select crossCompany specTrans
//            where specTrans.SpecCompany == _ledgerJournalTrans.company() &&
//                specTrans.SpecTableId == _ledgerJournalTrans.TableId &&
//                specTrans.SpecRecId == _ledgerJournalTrans.RecId
//            join custTransOpen
//                where specTrans.RefCompany == custTransOpen.DataAreaId &&
//                    specTrans.RefTableId == custTransOpen.TableId &&
//                    specTrans.RefRecId == custTransOpen.RecId
//            join custTrans
//                where custTransOpen.RefRecId == custTrans.RecId
//            join custTransCustomer
//                where custTrans.AccountNum == custTransCustomer.AccountNum
        while select crossCompany specTrans
            where   specTrans.SpecCompany       == _ledgerJournalTrans.company()
            &&      specTrans.SpecTableId       == _ledgerJournalTrans.TableId
            &&      specTrans.SpecRecId         == _ledgerJournalTrans.RecId
        join AmountCur, RefRecId
            from    custTransOpen
            where   specTrans.RefCompany        == custTransOpen.DataAreaId
            &&      specTrans.RefTableId        == custTransOpen.TableId
            &&      specTrans.RefRecId          == custTransOpen.RecId
        exists join custTransSelect
            where   custTransOpen.RefRecId      == custTransSelect.RecId
        exists join custTransCustomerSelect
            where   custTransSelect.AccountNum  == custTransCustomerSelect.AccountNum
// END
        {
// BEGIN
            custTrans           = CustTrans::find(custTransOpen.RefRecId);
            custTransCustomer   = CustTable::find(custTrans.AccountNum);
// END