Tuesday, January 26, 2016

AX 7

AX 7 Blog

http://daxture.blogspot.com.au/2016/01/ax-7-technical-insights.html

AX 7 is coming with a big technical change in the world of Microsoft ERP, Dynamics AX, in contrast to what we have, AX 2012. Developers get ready to adopt this change, there is a lot to learn relates to AX 7 development while supporting other versions of Dynamics AX.

Back to file system; Yes, with AX 7 we are back to file system. Any change (technical) we make in application is saved into file (XML file) at your disk.


Visual Studio will be used for all development stuff; MS developed visual studio extensions using standard Visual Studio extensions to enable the development of X++ code and AX 7 metadata in Visual Studio. 

Metadata API that communicate from visual studio with the XML files that are the source code on disk. Your source and metadata are the set of XML files now. Visual Studio user interface communicates with them with an API called Metadata API. 

Build from Visual Studio: When you build from Visual Studio, it compiles into assemblies and other binaries that runtime uses and during this whole process you are working against files. At this point in time there is no need for AOS to be running during design and compilation. 

Debug: Use standard visual studio paradigms to run and debug the code with F5 and Ctrl F5.

Runtime: It is the AOS and batch manager service which are running locally into your DEV box, the AOS is actually a web service in IIS.

Database: This is a standard SQL server database in your box, 

Deployment Package: It is a major change in AX 7. These Deployment Packages are compiled binary versions of your models and packages that can be deployed on the cloud. The cloud can be a test, UAT or production environment. 


Fetching Journal UnPosted transaction by Ledger from Cust/Vend/Bank/FA/Ledger ax 2012

// Fetching Journal UnPosted transaction by Ledger from Cust/Vend/Bank/FA/Ledger ax 2012

Table--> ledger Journal Trans
Display Amount AmountAccCur()
{
    if(this.Company != curext() && this.CurrencyCode == Ledger::accountingCurrency())
    {
        return decRound((this.AmountCurDebit + this.AmountCurCredit),3);
    }
    else
    {
        return decRound((this.ExchRate * (this.AmountCurDebit + this.AmountCurCredit)/100),3);
    }
}

Class-->
Description255   BankLedgerInforCode(Name _AccountNum,RecId   _TransRecId)
{
    Description255  BankLedInfo;
    LedgerJournalTrans          trans;
    ;
    trans.clear();
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    BankLedInfo = DimensionAttributeValueCombination::getDisplayValue(BankAccountTable::find(_AccountNum).LedgerDimension);
    return BankLedInfo;
}
Description255   BankLedgerInforCodeName(Name _AccountNum,RecId   _TransRecId)
{
    Description255  BankLedInfo;
    LedgerJournalTrans          trans;
    ;
    trans.clear();
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    BankLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(BankAccountTable::find(_AccountNum).LedgerDimension)).Name;
    return BankLedInfo;
}
Description255   CustLedgerInforCode(Name _AccountNum,RecId   _TransRecId)
{
    Description255  CustLedInfo;
    LedgerJournalTrans          trans;
    CustLedgerAccounts          ledgerscustAccounts,ledgerscustAccounts1,ledgerscustAccounts2;
    ;
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select firstonly SummaryLedgerDimension from ledgerscustAccounts
                            where ledgerscustAccounts.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts.AccountCode    == TableGroupAll::All;
    select firstonly SummaryLedgerDimension from ledgerscustAccounts1
                            where ledgerscustAccounts1.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts1.AccountCode    == TableGroupAll::GroupId
                                && ledgerscustAccounts1.Num          == CustTable::find(_AccountNum).CustGroup;
    select firstonly SummaryLedgerDimension from ledgerscustAccounts2
                            where ledgerscustAccounts2.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts2.AccountCode    == TableGroupAll::Table
                                && ledgerscustAccounts2.Num          == _AccountNum;

    if(ledgerscustAccounts)
    {
        CustLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts.SummaryLedgerDimension);
    }
    if(ledgerscustAccounts1)
    {
        CustLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts1.SummaryLedgerDimension);
    }
    if(ledgerscustAccounts2)
    {
        CustLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts2.SummaryLedgerDimension);
    }
    return CustLedInfo;
}
Description255   CustLedgerInforCodeName(Name _AccountNum,RecId   _TransRecId)
{
    Description255  CustLedInfo;
    LedgerJournalTrans          trans;
    CustLedgerAccounts          ledgerscustAccounts,ledgerscustAccounts1,ledgerscustAccounts2;
    ;
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select firstonly SummaryLedgerDimension from ledgerscustAccounts
                            where ledgerscustAccounts.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts.AccountCode    == TableGroupAll::All;
    select firstonly SummaryLedgerDimension from ledgerscustAccounts1
                            where ledgerscustAccounts1.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts1.AccountCode    == TableGroupAll::GroupId
                                && ledgerscustAccounts1.Num          == CustTable::find(_AccountNum).CustGroup;
    select firstonly SummaryLedgerDimension from ledgerscustAccounts2
                            where ledgerscustAccounts2.PostingProfile == trans.PostingProfile
                                && ledgerscustAccounts2.AccountCode    == TableGroupAll::Table
                                && ledgerscustAccounts2.Num          == _AccountNum;

    if(ledgerscustAccounts)
    {
        CustLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts.SummaryLedgerDimension)).Name;
    }
    if(ledgerscustAccounts1)
    {
        CustLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts1.SummaryLedgerDimension)).Name;
    }
    if(ledgerscustAccounts2)
    {
        CustLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgerscustAccounts2.SummaryLedgerDimension)).Name;
    }
    return CustLedInfo;
}
Description255   FALedgerInfoCode(Name _AccountNum,RecId   _TransRecId)
{
    Description255  FALedInfo;
    LedgerJournalTrans          trans;
    AssetLedgerAccounts         ledgersAssetAccounts,ledgersAssetAccounts1,ledgersAssetAccounts2;
    LedgerJournalTrans_Asset    transAsset;
    AssetTransType              AssetTransType;
    ;
    trans.clear();
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select transAsset
        where transAsset.RefRecId == trans.RecId;
    select firstonly LedgerDimension from ledgersAssetAccounts
                            where ledgersAssetAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAssetAccounts.BookId == transAsset.BookId
                                && ledgersAssetAccounts.AccountCode    == TableGroupAll::All
                                && ledgersAssetAccounts.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType));
    select firstonly LedgerDimension from ledgersAssetAccounts1
                        where ledgersAssetAccounts1.PostingProfile == trans.PostingProfile
                            && ledgersAssetAccounts1.BookId == transAsset.BookId
                            && ledgersAssetAccounts1.AccountCode    == TableGroupAll::GroupId
                            && ledgersAssetAccounts1.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType))
                            && ledgersAssetAccounts1.AccountRelation    == AssetTable::find(_AccountNum).AssetGroup;
    select firstonly LedgerDimension from ledgersAssetAccounts2
                        where ledgersAssetAccounts2.PostingProfile == trans.PostingProfile
                            && ledgersAssetAccounts2.BookId == transAsset.BookId
                            && ledgersAssetAccounts2.AccountCode    == TableGroupAll::Table
                            && ledgersAssetAccounts2.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType))
                            && ledgersAssetAccounts2.AccountRelation    == _AccountNum;
    if(ledgersAssetAccounts)
    {
        FALedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts.LedgerDimension);
    }
    if(ledgersAssetAccounts1)
    {
        FALedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts1.LedgerDimension);
    }
    if(ledgersAssetAccounts2)
    {
        FALedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts2.LedgerDimension);
    }
    return FALedInfo;
}
Description255   FALedgerInfoCodeName(Name _AccountNum,RecId   _TransRecId)
{
    Description255  FALedInfo;
    LedgerJournalTrans          trans;
    AssetLedgerAccounts         ledgersAssetAccounts,ledgersAssetAccounts1,ledgersAssetAccounts2;
    LedgerJournalTrans_Asset    transAsset;
    AssetTransType              AssetTransType;
    ;
    trans.clear();
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select transAsset
        where transAsset.RefRecId == trans.RecId;
    select firstonly LedgerDimension from ledgersAssetAccounts
                            where ledgersAssetAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAssetAccounts.BookId == transAsset.BookId
                                && ledgersAssetAccounts.AccountCode    == TableGroupAll::All
                                && ledgersAssetAccounts.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType));
    select firstonly LedgerDimension from ledgersAssetAccounts1
                        where ledgersAssetAccounts1.PostingProfile == trans.PostingProfile
                            && ledgersAssetAccounts1.BookId == transAsset.BookId
                            && ledgersAssetAccounts1.AccountCode    == TableGroupAll::GroupId
                            && ledgersAssetAccounts1.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType))
                            && ledgersAssetAccounts1.AccountRelation    == AssetTable::find(_AccountNum).AssetGroup;
    select firstonly LedgerDimension from ledgersAssetAccounts2
                        where ledgersAssetAccounts2.PostingProfile == trans.PostingProfile
                            && ledgersAssetAccounts2.BookId == transAsset.BookId
                            && ledgersAssetAccounts2.AccountCode    == TableGroupAll::Table
                            && ledgersAssetAccounts2.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType))
                            && ledgersAssetAccounts2.AccountRelation    == _AccountNum;
    if(ledgersAssetAccounts)
    {
        FALedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts.LedgerDimension)).Name;
    }
    if(ledgersAssetAccounts1)
    {
        FALedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts1.LedgerDimension)).Name;
    }
    if(ledgersAssetAccounts2)
    {
        FALedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts2.LedgerDimension)).Name;
    }
    return FALedInfo;
}
Description255   VendLedgerInfoCode(Name _AccountNum,RecId   _TransRecId)
{
    Description255              VendLedInfo;
    LedgerJournalTrans          trans;
    VendLedgerAccounts          ledgersAccounts,ledgersAccounts1,ledgersAccounts2;
    ;
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select firstonly SummaryLedgerDimension from ledgersAccounts
                            where ledgersAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAccounts.AccountCode    == TableGroupAll::All;
    select firstonly SummaryLedgerDimension from ledgersAccounts1
                            where ledgersAccounts1.PostingProfile == trans.PostingProfile
                                && ledgersAccounts1.AccountCode    == TableGroupAll::GroupId
                                && ledgersAccounts1.Num          == VendTable::find(_AccountNum).VendGroup;
    select firstonly SummaryLedgerDimension from ledgersAccounts2
                            where ledgersAccounts2.PostingProfile == trans.PostingProfile
                                && ledgersAccounts2.AccountCode    == TableGroupAll::Table
                                && ledgersAccounts2.Num          == _AccountNum;

    if(ledgersAccounts)
    {
        VendLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts.SummaryLedgerDimension);
    }
    if(ledgersAccounts1)
    {
        VendLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts1.SummaryLedgerDimension);
    }
    if(ledgersAccounts2)
    {
        VendLedInfo = DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts2.SummaryLedgerDimension);
    }

    return VendLedInfo;
}
Description255   VendLedgerInfoCodeName(Name _AccountNum,RecId   _TransRecId)
{
    Description255              VendLedInfo;
    LedgerJournalTrans          trans;
    VendLedgerAccounts          ledgersAccounts,ledgersAccounts1,ledgersAccounts2;
    ;
    trans = LedgerJournalTrans::findRecId(_TransRecId,false);
    select firstonly SummaryLedgerDimension from ledgersAccounts
                            where ledgersAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAccounts.AccountCode    == TableGroupAll::All;
    select firstonly SummaryLedgerDimension from ledgersAccounts1
                            where ledgersAccounts1.PostingProfile == trans.PostingProfile
                                && ledgersAccounts1.AccountCode    == TableGroupAll::GroupId
                                && ledgersAccounts1.Num          == VendTable::find(_AccountNum).VendGroup;
    select firstonly SummaryLedgerDimension from ledgersAccounts2
                            where ledgersAccounts2.PostingProfile == trans.PostingProfile
                                && ledgersAccounts2.AccountCode    == TableGroupAll::Table
                                && ledgersAccounts2.Num          == _AccountNum;
    if(ledgersAccounts)
    {
        VendLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts.SummaryLedgerDimension)).Name;
    }
    if(ledgersAccounts1)
    {
        VendLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts1.SummaryLedgerDimension)).Name;
    }
    if(ledgersAccounts2)
    {
        VendLedInfo = MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts2.SummaryLedgerDimension)).Name;
    }

    return VendLedInfo;
}
private void insertLedgerJournalTmp(
    LedgerJournalTable _ledgerJournalTable,
    LedgerJournalTrans _ledgerJournalTrans,
    AccountOffsetaccount _accountOffsetAccount = AccountOffsetaccount::Account)
{
    StagTmpTable.JournalId = _ledgerJournalTable.JournalNum;
    StagTmpTable.TransRecId = _ledgerJournalTrans.RecId;
    if(_accountOffsetAccount == AccountOffsetaccount::OffsetAccount
        && _ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Ledger)
    {
        StagTmpTable.AccountType = _ledgerJournalTrans.OffsetAccountType;
        StagTmpTable.LedgerDimension = _ledgerJournalTrans.OffsetLedgerDimension;
    }
    else
    {
        StagTmpTable.AccountType = _ledgerJournalTrans.AccountType;
        StagTmpTable.LedgerDimension = _ledgerJournalTrans.LedgerDimension;
    }
    StagTmpTable.Company = _ledgerJournalTrans.Company;
    StagTmpTable.CurrencyCode = _ledgerJournalTrans.CurrencyCode;
    StagTmpTable.Voucher = _ledgerJournalTrans.Voucher;
    StagTmpTable.TransDate = _ledgerJournalTrans.TransDate;
    StagTmpTable.AmountCurCredit = _ledgerJournalTrans.AmountCurCredit;
    StagTmpTable.AmountCurDebit = _ledgerJournalTrans.AmountCurDebit;
    StagTmpTable.AccountOffsetaccount = _accountOffsetAccount;
    StagTmpTable.TXT = _ledgerJournalTrans.Txt;
    StagTmpTable.ExchRate = _ledgerJournalTrans.ExchRate/100;
    StagTmpTable.Insert();
}

private LedgerJournalTrans ledgerJournalTransOffset(LedgerJournalTrans _ledgerJournalTrans)
{
    AmountCur amountCurLocal;
    if (_ledgerJournalTrans.parmOffsetLedgerDimension())
    {
        if (_ledgerJournalTrans.ledgerJournalTable().LedgerJournalInclTax)
        {
            if (!(_ledgerJournalTrans.AccountType != LedgerJournalACType::Ledger &&
                  _ledgerJournalTrans.AccountType != LedgerJournalACType::Project &&
                 (_ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Ledger ||
                  _ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Project)))
            {
                _ledgerJournalTrans.TaxGroup = '';
                _ledgerJournalTrans.TaxItemGroup = '';
                _ledgerJournalTrans.TaxCode = '';
            }
        }
        else
        {
            if ((_ledgerJournalTrans.AccountType == LedgerJournalACType::Ledger       ||
                 _ledgerJournalTrans.AccountType == LedgerJournalACType::Project)     &&
                (_ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Ledger ||
                 _ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Project))
            {
                _ledgerJournalTrans.TaxGroup = '';
                _ledgerJournalTrans.TaxItemGroup = '';
                _ledgerJournalTrans.TaxCode = '';
            }
        }
        _ledgerJournalTrans.parmLedgerDimension(_ledgerJournalTrans.parmOffsetLedgerDimension());
        _ledgerJournalTrans.parmDefaultDimension(_ledgerJournalTrans.parmOffsetDefaultDimension());
        _ledgerJournalTrans.AccountType = _ledgerJournalTrans.OffsetAccountType;
        _ledgerJournalTrans.Company = _ledgerJournalTrans.OffsetCompany ? _ledgerJournalTrans.OffsetCompany : _ledgerJournalTrans.Company;
        _ledgerJournalTrans.Txt = _ledgerJournalTrans.OffsetTxt ? _ledgerJournalTrans.OffsetTxt : _ledgerJournalTrans.Txt;
        amountCurLocal = _ledgerJournalTrans.AmountCurDebit;
        _ledgerJournalTrans.AmountCurDebit = _ledgerJournalTrans.AmountCurCredit;
        _ledgerJournalTrans.AmountCurCredit = amountCurLocal;
        _ledgerJournalTrans.parmOffsetLedgerDimension(0);
    }
    else
    {
        _ledgerJournalTrans.parmLedgerDimension(0);
        _ledgerJournalTrans.AmountCurDebit = 0;
        _ledgerJournalTrans.AmountCurCredit = 0;
    }
    return _ledgerJournalTrans;
}

private void ProcessReportUnPosted()
{
    LedgerJournalTrans                  Journaltrans;
    LedgerJournalTable                  Journaltable;
    FromDate        fromdate;
    ToDate          todate;
    MainAccountNum AccountNum;
    Fcc_LedgerPostedAndNotPostedContract contract;
    ;
    contract = this.parmDataContract() as Fcc_LedgerPostedAndNotPostedContract;
    AccountNum = contract.parmmainaccount();
    fromdate = contract.parmFromDate();
    todate = contract.parmToDate();
    delete_from     StagTmpTable;
    //Inserting Open Journal Transaction
    while select Journaltable
            where Journaltable.posted == NoYes::no
        join Journaltrans where Journaltrans.JournalNum == Journaltable.JournalNum
            && Journaltrans.TransDate >= fromdate
                    && Journaltrans.TransDate <= todate
    {
        this.insertLedgerJournalTmp(Journaltable, Journaltrans,AccountOffsetaccount::Account);
        Journaltrans = this.ledgerJournalTransOffset(Journaltrans);
        if (Journaltrans.parmLedgerDimension())
        {
            this.insertLedgerJournalTmp(Journaltable, Journaltrans,AccountOffsetaccount::OffsetAccount);
        }
    }
    //Updating Account Name for Open Transaction
        this.UpdateStagTmpAccountName();
        //updating Ledger Account for all Open Transaction
    StagTmpTable.clear();
        ttsBegin;
        while select forUpdate StagTmpTable
                where StagTmpTable.AccountType == LedgerJournalACType::Vend
                    || StagTmpTable.AccountType == LedgerJournalACType::Cust
                    || StagTmpTable.AccountType == LedgerJournalACType::FixedAssets
                    || StagTmpTable.AccountType == LedgerJournalACType::Bank
                    || StagTmpTable.AccountType == LedgerJournalACType::Ledger
        {
            if(StagTmpTable.AccountType == LedgerJournalACType::Vend)
            {
                StagTmpTable.AccountName = this.VendLedgerInfoCodeName(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                StagTmpTable.AccountNum  = this.VendLedgerInfoCode(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                if(StagTmpTable.AmountCurCredit != 0)
                {
                    StagTmpTable.AmountCurCredit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
                if(StagTmpTable.AmountCurDebit != 0)
                {
                    StagTmpTable.AmountCurDebit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
            }
            if(StagTmpTable.AccountType == LedgerJournalACType::Cust)
            {
                StagTmpTable.AccountName = this.CustLedgerInforCodeName(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                StagTmpTable.AccountNum  = this.CustLedgerInforCode(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                if(StagTmpTable.AmountCurCredit != 0)
                {
                    StagTmpTable.AmountCurCredit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
                if(StagTmpTable.AmountCurDebit != 0)
                {
                    StagTmpTable.AmountCurDebit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
            }
            if(StagTmpTable.AccountType == LedgerJournalACType::FixedAssets)
            {
                StagTmpTable.AccountName = this.FALedgerInfoCodeName(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                StagTmpTable.AccountNum  = this.FALedgerInfoCode(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                if(StagTmpTable.AmountCurCredit != 0)
                {
                    StagTmpTable.AmountCurCredit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
                if(StagTmpTable.AmountCurDebit != 0)
                {
                    StagTmpTable.AmountCurDebit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
            }
            if(StagTmpTable.AccountType == LedgerJournalACType::Bank)
            {
                StagTmpTable.AccountName = this.BankLedgerInforCodeName(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                StagTmpTable.AccountNum  = this.BankLedgerInforCode(StagTmpTable.AccountNum,StagTmpTable.TransRecId);
                if(StagTmpTable.AmountCurCredit != 0)
                {
                    StagTmpTable.AmountCurCredit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
                if(StagTmpTable.AmountCurDebit != 0)
                {
                    StagTmpTable.AmountCurDebit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
            }
            if(StagTmpTable.AccountType == LedgerJournalACType::Ledger)
            {
                StagTmpTable.AccountNum  = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).LedgerDimensionValue("MainAccount",StagTmpTable.AccountOffsetaccount);
                StagTmpTable.AccountName  = MainAccount::findByMainAccountId(LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).LedgerDimensionValue("MainAccount",StagTmpTable.AccountOffsetaccount)).Name;
                if(StagTmpTable.AmountCurCredit != 0)
                {
                    StagTmpTable.AmountCurCredit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
                if(StagTmpTable.AmountCurDebit != 0)
                {
                    StagTmpTable.AmountCurDebit = LedgerJournalTrans::findRecId(StagTmpTable.TransRecId,false).AmountAccCur();
                }
            }
            StagTmpTable.Update();
        }
        ttsCommit;
}

Inter company Posting GL With Ledger Dimension

// Inter company Posting GL With Ledger Dimension

// Issue : Inter company Journal not retrieving Dimension while posting IC Ledger

update code

Class--> LedgerJournalTransUpdate
Method--> updateInterCompany
Line Number --> 61

//interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimension(defaultAccount));

interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceMergeLedgerDimensions(defaultAccount,_ledgerJournalTrans.LedgerDimension)); 

/// customize

//interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimension(defaultAccount));
       
        if(_ledgerJournalTrans.AmountCurDebit > 0)
        {
            select firstOnly journalTrans
                where journalTrans.JournalNum == _ledgerJournalTrans.JournalNum
                    && journalTrans.Company == curext()
                    && journalTrans.AmountCurCredit > 0;
            if(journalTrans.AccountType == LedgerJournalACType::Ledger)
            {               
interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceMergeLedgerDimensions(defaultAccount, journalTrans.LedgerDimension));
            }
            else if(journalTrans.AccountType != LedgerJournalACType::Ledger)
            {               
interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimension(defaultAccount, journalTrans.DefaultDimension));
            }
        }
        else if(_ledgerJournalTrans.AmountCurCredit > 0)
        {
            select firstOnly journalTrans
                where journalTrans.JournalNum == _ledgerJournalTrans.JournalNum
                    && journalTrans.Company == curext()
                    && journalTrans.AmountCurDebit > 0;
            if(journalTrans.AccountType == LedgerJournalACType::Ledger)
            {               
interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceMergeLedgerDimensions(defaultAccount, journalTrans.LedgerDimension));
            }
            else if(journalTrans.AccountType != LedgerJournalACType::Ledger)
            {               
interCompanyTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimension(defaultAccount, journalTrans.DefaultDimension));
            }
        }
//End Code



Thursday, January 21, 2016

To Get Posting profile account of Vend/Cust/FA/Bank in ax 2012

// get Posting profile account of Vend/Cust/FA/Bank in ax 2012
static void  vendCustAssetBankPPtest(Args _args)
{
    LedgerJournalTrans  trans;
    VendLedgerAccounts  ledgersAccounts,ledgersAccounts1,ledgersAccounts2;
    CustLedgerAccounts  ledgerscustAccounts,ledgerscustAccounts1,ledgerscustAccounts2;
    AssetLedgerAccounts  ledgersAssetAccounts,ledgersAssetAccounts1,ledgersAssetAccounts2;
    LedgerJournalTrans_Asset    transAsset;
    AssetTransType  AssetTransType;
    ;
    trans = LedgerJournalTrans::findRecId(5637158839,false);
    select firstonly SummaryLedgerDimension from ledgersAccounts
                            where ledgersAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAccounts.AccountCode    == TableGroupAll::All;
    select firstonly SummaryLedgerDimension from ledgersAccounts1
                            where ledgersAccounts1.PostingProfile == trans.PostingProfile
                                && ledgersAccounts1.AccountCode    == TableGroupAll::GroupId
                                && ledgersAccounts1.Num          == VendTable::find("CDM0002").VendGroup;
    select firstonly SummaryLedgerDimension from ledgersAccounts2
                            where ledgersAccounts2.PostingProfile == trans.PostingProfile
                                && ledgersAccounts2.AccountCode    == TableGroupAll::Table
                                && ledgersAccounts2.Num          == "CDM0002";
    info(strFmt("%1",trans.PostingProfile));
    info(strFmt("%1",ledgersAccounts.SummaryLedgerDimension));
    info(strFmt("All - %1",DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts.SummaryLedgerDimension)));
    info(strFmt("All name - %1",MainAccount::findByMainAccountId(DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts.SummaryLedgerDimension)).Name));
    info(strFmt("Group %1",DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts1.SummaryLedgerDimension)));
    info(strFmt("Table %1",DimensionAttributeValueCombination::getDisplayValue(ledgersAccounts2.SummaryLedgerDimension)));
   
    trans.clear();
    trans = LedgerJournalTrans::findRecId(5637160338,false);
    info(strFmt("%1",DimensionAttributeValueCombination::getDisplayValue(BankAccountTable::find("GBK-USDACC").LedgerDimension)));
   
    trans.clear();
    trans = LedgerJournalTrans::findRecId(5637160335,false);
    select transAsset where transAsset.RefRecId == trans.RecId;
    info(strFmt("%1-%2",transAsset.TransType,transAsset.BookId));
//Same for Account code group,Table
    select firstonly LedgerDimension from ledgersAssetAccounts
                            where ledgersAssetAccounts.PostingProfile == trans.PostingProfile
                                && ledgersAssetAccounts.BookId == transAsset.BookId
                                && ledgersAssetAccounts.AccountCode    == TableGroupAll::All
                                //&& ledgersAssetAccounts.AccountRelation          == "CDM0002"
                                && ledgersAssetAccounts.TransType == str2enum(AssetTransType,enum2str(transAsset.TransType));
    info(strFmt("%1",ledgersAssetAccounts.LedgerDimension));
    info(strFmt("%1",DimensionAttributeValueCombination::getDisplayValue(ledgersAssetAccounts.LedgerDimension)));
}

Budget Entries Upload

//Creation of Budget header and Lines through Class in AX 2012

Excel Template
BudgetCode,
BudgetModel,
AccountStructure,
Date,
Amount,
AmountType,
MainAccount,
BusinessUnit,Department,
CostCenter

class San_ImportBudget extends RunBase
{
    // Packed variables
    Filename            importFileName;
    container           accountSegments;
    container           accountSegmentNames;
    BudgetCode          budgetCode;
    BudgetModelId       budgetModelId;
    Name                accountStructureName;
    TransDate           transDate;
    AmountCur           amount;
    BudgetType          budgetType;
    MainAccountNum      mainAccountNum;


    // Dialog fields
    DialogField     dlgImportFileName;

    #define.CurrentVersion(1)
    #define.Version1(1)
    #localmacro.CurrentList
        importFileName
    #endmacro

    BudgetTransactionService            budgetTransactionService;
    BudgetTransaction                   budgetTransaction;
    BudgetTransaction_BudgetTransHeader budgetTransaction_BudgetTransHeader;

    str fileName;
    str filePath;
    str fileExtension;
}

public str COMVariant2Str(COMVariant _cv,
                       int _decimals = 1,
                       int _characters = 0,
                       int _separator1 = 0,
                       int _separator2 = 0)
{
    switch(_cv.variantType())
    {
        case (COMVariantType::VT_BSTR):
            return _cv.bStr();

        case (COMVariantType::VT_R4):
            return num2str(_cv.float(),
                           _characters,
                           _decimals,
                           _separator1,
                           _separator2);

        case (COMVariantType::VT_R8):
             return num2str(_cv.double(),
                            _characters,
                            _decimals,
                            _separator1,
                            _separator2);

        case (COMVariantType::VT_DECIMAL):
             return num2str(_cv.decimal(),
                            _characters,
                            _decimals,
                            _separator1,
                            _separator2);

        case (COMVariantType::VT_DATE):
             return date2str(_cv.date(),
                             213,
                             2,
                             1,
                             2,
                             1,
                             4);

        case (COMVariantType::VT_EMPTY):
             return "";

        default:
             throw error(strfmt("@SYS26908", _cv.variantType()));
    }

    return "";
}

public Object dialog()
{
    DialogRunbase       dialog = super();
    #resAppl
    #AviFiles
    #Excel
    ;

    dlgImportFileName = dialog.addField(ExtendedTypeStr(FileNameOpen), "File name");
    dlgImportFileName.value(importFileName);
    dialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS,"@SYS100852","*.csv","Text","*.txt"]);
    return dialog;
}


public boolean getFromDialog()
{
    importFileName = dlgImportFileName.value();
    return super();
}

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
;
    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }

    return true;
}

static void main(Args args)
{
    San_ImportBudget    budgetImport = new San_ImportBudget();

    if (budgetImport.prompt())
        budgetImport.run();
}

public void run()
{
    #OCCRetryCount
    if (! this.validate())
        throw error("");

    try
    {
        ttsbegin;

        [filePath, fileName, fileExtension] = fileNameSplit(importFileName);

        switch (fileExtension)
        {
            case ".xls", ".xlsx" :
                info("@SYS4010033");
                this.ProcessImportXLSFile();
                info("@SYS329919");
                break;
            default :
                info(strFmt("Unable to process file of type %1",fileExtension));
                info("File must be .xls or .xlsx");
                break;
        }

        ttscommit;
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }
    catch (Exception::Error)
    {
        ttsAbort;
        info('Failed to post, reversing updates');
    }


}

private void ProcessImportXLSFile()
{
    SysExcelApplication excel;
    SysExcelWorkbooks   workbooks;
    SysExcelWorkbook    workbook;
    SysExcelWorksheets  worksheets;
    SysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    SysExcelCell        cell;
    COMVariantType      type;
    COMVariantType      hdrtype;
    container           header;
    int                 row = 1;
    int                 totalColumnCount = 0;
    int                 currentColumn;

    excel = SysExcelApplication::construct();
    excel.visible(false);

    workbooks = excel.workbooks();

    try
    {
        workbooks.open(importFileName);
    }
    catch (Exception::Error)
    {
        throw error(strFmt('@GLS101746', importFileName));
    }

    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    type = cells.item(row+1,1).value().variantType();

    if (type == COMVariantType::VT_EMPTY || type == COMVariantType::VT_NULL || type == COMVariantType::VT_UNKNOWN)
    {
        error("@SYS102111");
    }
    else
    {
        // recover header column names
        for (currentColumn=1; currentColumn < 99; currentColumn++)
        {
            hdrtype = cells.item(row,currentColumn).value().variantType();
            if (hdrtype != COMVariantType::VT_EMPTY)
            {
                header += cells.item(row, currentColumn).value().bStr();
                totalColumnCount++;
            }
            else
            {
                break;
            }
        }

        type = cells.item(row+1, 1).value().variantType();
        while (type != COMVariantType::VT_EMPTY && type != COMVariantType::VT_NULL && type != COMVariantType::VT_UNKNOWN)
        {
            row++;
            accountSegments = conNull();
            accountSegmentNames = conNull();

            budgetCode = this.COMVariant2Str(cells.item(row, 1).value(), 0);
            budgetModelId = this.COMVariant2Str(cells.item(row, 2).value(), 0);
            accountStructureName = this.COMVariant2Str(cells.item(row, 3).value(), 0);
            transDate = str2Date(this.COMVariant2Str(cells.item(row, 4).value(), 0),213);
            amount = str2num(this.COMVariant2Str(cells.item(row, 5).value(), 2));
            budgetType = str2enum(budgetType, this.COMVariant2Str(cells.item(row, 6).value(), 0));
            mainAccountNum = this.COMVariant2Str(cells.item(row, 7).value(), 0);

            //The remaining columns are account segments and there can be any number of them
            for(currentColumn = 8; currentColumn <= totalColumnCount; currentColumn++)
            {
                //Read the remaining segment columns as strings and put into a container
                accountSegments += this.COMVariant2Str(cells.item(row, currentColumn).value(), 0);
                accountSegmentNames += conPeek(header, currentColumn);
            }

            this.createBudgetTransactionLine();

            type = cells.item(row+1, 1).value().variantType();
        }

        BudgetTransactionService.create(budgetTransaction);
    }

    excel.quit();
}

public void createBudgetTransactionLine()
{
    BudgetTransaction_BudgetTransLine   budgetTransaction_BudgetTransLine;

    AifBudgetAccount                    aifBudgetAccount;
    AifDimensionAttributeValue          aifDimensionAttributeValue;
    int                                 dimensionColumn;

    if (!budgetTransactionService)
    {
        budgetTransactionService                = BudgetTransactionService::construct();
        budgetTransaction                       = new BudgetTransaction();
        budgetTransaction_BudgetTransHeader     = budgetTransaction.createBudgetTransHeader().addNew();
        budgetTransaction_BudgetTransHeader.parmBudgetTransactionCode(budgetCode);
        budgetTransaction_BudgetTransHeader.parmBudgetModelId(budgetModelId);
        budgetTransaction_BudgetTransLine       = budgetTransaction_BudgetTransHeader.createBudgetTransLine().addNew();
    }
    else
    {
        budgetTransaction_BudgetTransLine       = budgetTransaction_BudgetTransHeader.parmBudgetTransLine().addNew();
    }

    // Populate the budget line
    budgetTransaction_BudgetTransLine.parmDate(transDate);
    budgetTransaction_BudgetTransLine.parmTransactionCurrencyAmount(amount);
    budgetTransaction_BudgetTransLine.parmBudgetType(budgetType);

    aifBudgetAccount   = budgetTransaction_BudgetTransLine.createLedgerDimension();
    aifBudgetAccount.parmAccountStructure(accountStructureName);
    aifBudgetAccount.parmDisplayValue("1");    //Will be changed by system to write display value

    // Main Account - required
    aifDimensionAttributeValue   = aifBudgetAccount.createValues().addNew();
    aifDimensionAttributeValue.parmName('MainAccount');
    aifDimensionAttributeValue.parmValue(mainAccountNum);

    // variable dimension list - optional
    if (conLen(accountSegments) > 0)
    {
        for (dimensionColumn = 1; dimensionColumn <= conLen(accountSegments); dimensionColumn++)
        {
            if(conPeek(accountSegments, dimensionColumn) != "")
            {
                aifDimensionAttributeValue = aifBudgetAccount.parmValues().addNew();
                aifDimensionAttributeValue.parmName(conPeek(accountSegmentNames, dimensionColumn));
                aifDimensionAttributeValue.parmValue(conPeek(accountSegments, dimensionColumn));
            }
        }
    }
}


End

//Only budget transaction line upload - in within Budget Transaction entries Form

void clicked()
{
    BudgetTransactionLine transLine;
    super();
    transLine.BudgetTransactionHeader = BudgetTransactionHeader.RecId;
    transLine.Date = today();
    transLine.LineNumber =1;
    transLine.BudgetType = BudgetType::Expense;
    transLine.LedgerDimension = 5637155864;
    transLine.TransactionCurrency = "KWD";
    transLine.editTransactionCurrencyAmount(true,100);
    transLine.insert();
    BudgetTransactionLine_Ds.editAccountStructure(true,transLine,"FCCI");
    BudgetTransactionLine_Ds.research();
    transLine.clear();
    transLine.BudgetTransactionHeader = BudgetTransactionHeader.RecId;
    transLine.LineNumber =2;
    transLine.Date = today();
    transLine.BudgetType = BudgetType::Expense;
    transLine.LedgerDimension = 5637155859;
    transLine.TransactionCurrency = "USD";
    transLine.editTransactionCurrencyAmount(true,200);
    transLine.insert();
    BudgetTransactionLine_Ds.editAccountStructure(true,transLine,"FCCI");
    BudgetTransactionLine_Ds.research();
    transLine.clear();
    transLine.BudgetTransactionHeader = BudgetTransactionHeader.RecId;
    transLine.LineNumber =3;
    transLine.Date = today();
    transLine.BudgetType = BudgetType::Expense;
    transLine.LedgerDimension = 5637155862;
    transLine.TransactionCurrency = "USD";
    transLine.editTransactionCurrencyAmount(true,300);
    transLine.insert();
    BudgetTransactionLine_Ds.editAccountStructure(true,transLine,"FCCI");
    BudgetTransactionLine_Ds.research();
}

Opening and closing balance Mainaccount ax 2012

static void MainAccountTrialBalCheck(Args _args)
{
    LedgerTrialBalanceDP trialBalanceDP = new LedgerTrialBalanceDP();
    LedgerTrialBalanceContract trialBalanceContract = new LedgerTrialBalanceContract();
    LedgerTrialBalanceTmp trialBalanceTmp;
    LedgerTrialBalanceListPageTmp   _Tmp;
    DimensionHierarchy dimHier;
    UserConnection userConn;
    ;
    ttsBegin;
    dimHier = DimensionHierarchy::getMainAccountFocus();
    //DimensionFocusUpdateBalance::updateBalance(
        //DimensionHierarchy::findByTypeAndName(DimensionHierarchyType::Focus, dimHier.Name),true);
    userConn = new UserConnection();
    trialBalanceTmp.setConnection(userConn);
    _tmp.setConnection(userConn);
    trialBalanceContract.parmDetailSummary(DetailSummary::Summary);
    trialBalanceContract.parmFromDate(mkDate(01,07,2015));
    trialBalanceContract.parmToDate(mkDate(31,12,2015));
    trialBalanceContract.parmIncludeOpening(False);
    trialBalanceContract.parmIncludeClosing(False);
    trialBalanceContract.parmOperationsTax(OperationsTax::Current);
    trialBalanceContract.parmPrimaryDimensionFocus(dimHier.Name);

    trialBalanceDP.parmDataContract(trialBalanceContract);
    trialBalanceDP.parmUserConnection(userConn);
    trialBalanceDP.processReport();

    _tmp.recordLevelSecurity(false);
    trialBalanceTmp = trialBalanceDP.getLedgerTrialBalanceTmp();
    insert_recordset _tmp (PrimaryFocus, LedgerDimension, OpeningBalance, AmountDebit, AmountCredit, ClosingBalance, EndingBalance, Description, DimensionValues)
        select PrimaryFocus, LedgerDimension, OpeningBalance, AmountDebit, AmountCredit, ClosingBalance, EndingBalance, PrimaryFocusDescription, DimensionValues
        from trialBalanceTmp;

    _tmp.recordLevelSecurity(true);

    //while select sum(OpeningBalance),sum(AmountDebit),sum(AmountCredit),sum(EndingBalance)
            //from trialBalanceTmp
                //group by LedgerDimension
    while select trialBalanceTmp
    {
        info(strFmt("%1;%2;%3;%4;%5",DimensionAttributeValueCombination::find(trialBalanceTmp.LedgerDimension).DisplayValue,
                                    trialBalanceTmp.OpeningBalance,
                                    trialBalanceTmp.AmountDebit,
                                    trialBalanceTmp.AmountCredit,
                                    trialBalanceTmp.EndingBalance));
    }
    ttsCommit;
}

Get Workflow Multiple approval users ax 2012

static void  WorkflowTest(Args _args)
{
    WorkflowTrackingStatusTable workflowTrackingStatusTable;
    WorkflowTrackingTable WorkflowTrackingTable;
    WorkflowApprovalName approvername;
    boolean first = true;   
    container       approver;
    int i;
    ;
   
    while select workflowtrackingstatustable
            where workflowtrackingstatustable .ContextRecId == 5637146089
                && workflowtrackingstatustable.WorkflowType == WorkflowTrackingStatusWorkflowType::Workflow
                && workflowtrackingstatustable.TrackingStatus == WorkflowTrackingStatus::Completed
    join workflowtrackingtable order by RecId Asc
    where  workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem
    && (workflowtrackingtable.TrackingType == workflowtrackingtype::Approval
        || workflowtrackingtable.TrackingType == workflowtrackingtype::Completion)
    && workflowtrackingtable.WorkflowTrackingStatusTable == workflowtrackingstatustable .recid
    {
        if(first)
        {
            first = false;
            continue;
        }
        else
        {
            approver += workflowtrackingtable.User;
            //approvername = workflowtrackingtable.User;
            //info(strFmt("%1",approvername));
        }
    }
    for(i=1;i<=conLen(approver);i++)
    {
        approvername = conPeek(approver,i);
        info(strFmt("%1",approvername));
    }
   
}

Enable report server errors SQL

USE ReportServer
GO

UPDATE ConfigurationInfo
SET Value = 'True'
WHERE Name = 'EnableRemoteErrors'

Get Default Dimension value and Names in ax 2012

// Get Default Dimension value and Names in ax 2012
static void GetDefaultDimensionAttributeName(Args _args)
{
    DimensionAttributeValueSetStorage    dimStorage;
   
    DimensionAttribute  DimensionAttribute;
    Counter                                               i;
    DimensionAttribute          dimAttr;
    DimensionAttributeValue     dimAttrValue;
    Common                      common;
    DictTable                   dictTable;
    str                         Name;
    str                         value;
  
    dimStorage = DimensionAttributeValueSetStorage::find(5637155830);
    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        // get attribute select here.
        select firstonly dimAttrValue
        where dimAttrValue.RecId == dimStorage.getValueByIndex(i)
        join dimAttr
            where dimAttr.RecId == dimAttrValue.DimensionAttribute
                && dimAttr.Name == "Department";
        if (dimAttr && dimAttrValue)
        {
            dictTable = new DictTable(dimAttr.BackingEntityType);
            common = dictTable.makeRecord();
            if (common.TableId)
            {
                select common where common.(dimAttr.KeyAttribute) == dimAttrValue.EntityInstance;
                name = common.(dimAttr.NameAttribute);
                value = common.(dimAttr.ValueAttribute);
                info(dimAttr.Name +"----" +value + "----"+name);
            }
        }
       
    }
}

Upload data from Excel in D365FO X++

 Action Menu Item: SAN_UploadExcelData Object type: Class Object: <Controller class name> Label: <> Class: Controller class clas...