Search This Blog

Friday, July 6, 2012

Import Financial Ledger Budget in AX2012 using BudgetTransactionService

Import Financial Ledger Budget using BudgetTransactionService


class budgetTransactionLine 
{
    BudgetModelId                       budgetModelId;
    DialogField                         dlgBudgetModelId;

    #Define.Name(1)
    #Define.Date(2)
    #Define.FinancialAccount(3)
    #Define.Amount(4)
    #Define.budgetCode(5)
 

    DimensionHierarchyId                accountStructureHierarchy;
    DialogField                         dlgAccountStructureHierarchy;

    BudgetTransactionService            budgetTransactionService;
    BudgetTransaction                   budgetTransaction;
    BudgetTransaction_BudgetTransHeader budgetTransaction_BudgetTransHeader;

    #define.CurrentVersion(1)
    #localmacro.CurrentList
        budgetModelId
        , budgetCode
        , accountStructureHierarchy
    #endmacro
}

// add the dialog field to which account hierarchy we have to import,what was the model

public Object dialog(Dialog _dialog)
{
    ;
    _dialog = super(_dialog);

    _dialog.addGroup("Budgeting");
    dlgAccountStructureHierarchy    = _dialog.addFieldValue(extendedTypeStr(DimensionHierarchyId), accountStructureHierarchy , "@SYS310383");
    dlgBudgetModelId                = _dialog.addFieldValue(extendedTypeStr(BudgetModelId), budgetModelId);
     return _dialog;
}


public boolean getFromDialog()
{
    boolean ret;

    ret = super();

    budgetModelId               = dlgBudgetModelId.value();

    accountStructureHierarchy   = dlgAccountStructureHierarchy.value();

    return ret;
}


public void createBudgetTransactionLine(
    TransDate                               _transDate
    , MainAccountNum                        _mainAccountNum
    , AmountCur                             _amountCur
    , str                                   _department
    , BudgetModelId                         _budgetModelId = budgetModelId )
{
    BudgetTransaction_BudgetTransLine   budgetTransaction_BudgetTransLine;

    AifBudgetAccount                    aifBudgetAccount;
    AifDimensionAttributeValue          aifDimensionAttributeValue;
    ;

    if (!budgetTransactionService)
    {
        budgetTransactionService                = BudgetTransactionService::construct();

        budgetTransaction                       = new budgetTransaction();

        budgetTransaction_BudgetTransHeader     = budgetTransaction.createBudgetTransHeader().addNew();
        budgetTransaction_BudgetTransHeader.parmBudgetModelId(budgetModelId);
        budgetTransaction_BudgetTransLine       = budgetTransaction_BudgetTransHeader.createBudgetTransLine().addNew();
    }
    else
    {
        budgetTransaction_BudgetTransLine       = budgetTransaction_BudgetTransHeader.parmBudgetTransLine().addNew();
    }

    budgetTransaction_BudgetTransLine.parmDate(_transDate);
    budgetTransaction_BudgetTransLine.parmTransactionCurrencyAmount(_amountCur);

// assigning the Financial dimensions for that main account and department.

    if (_mainAccountNum)
    {
        if (!aifBudgetAccount)
        {
            aifBudgetAccount   = budgetTransaction_BudgetTransLine.createLedgerDimension();
            aifBudgetAccount.parmAccountStructure(DimensionHierarchy::find(accountStructureHierarchy).Name);
            aifBudgetAccount.parmDisplayValue("1");//Will be changed by system to wright display value

            aifDimensionAttributeValue   = aifBudgetAccount.createValues().addNew();
        }
        else
        {
            aifDimensionAttributeValue = aifBudgetAccount.parmValues().addNew();
        }

        aifDimensionAttributeValue.parmName("Mainaccount");
        aifDimensionAttributeValue.parmValue(_mainAccountNum);
    }

    if (_department)
    {
        if (!aifBudgetAccount)
        {
            aifBudgetAccount   = budgetTransaction_BudgetTransLine.createLedgerDimension();
            aifBudgetAccount.parmAccountStructure(DimensionHierarchy::find(accountStructureHierarchy).Name);
            aifBudgetAccount.parmDisplayValue("2");//Will be changed by system to wright display value

            aifDimensionAttributeValue   = aifBudgetAccount.createValues().addNew();
        }
        else
        {
            aifDimensionAttributeValue = aifBudgetAccount.parmValues().addNew();
        }

        aifDimensionAttributeValue.parmName("Department");
        aifDimensionAttributeValue.parmValue(_department);

// this will creates the lines
      BudgetTransactionService.create(budgetTransaction);
    }



// before this you have to read from the CSV and get the container from that read.
//If you want to see how to read from CSV sample you can check my previous posts how to get the container from csv file
 http://krishhdax.blogspot.dk/2012/03/ax2012-import-ledger-journal-trans-from.html

public void run()
{
 this.
createBudgetTransactionLine(


        str2date((conPeek(_item, #Dato))
        , conPeek(_item, #Finanskonto)
        , str2num((conPeek(_item, #Beloeb))
       
 );


}






2 comments:

  1. Thank you very very much Khrisna
    you help me a lot with this post.
    God bless you!
    do you have post about outbound/inbound AIF service?
    I want to learn about AIF..Thanks once again.
    Regards,
    Shamgar yudoyono.

    ReplyDelete
  2. Hi Krish, thanks for your post, if i want just add new line, how i can use that class?

    Regards
    David

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.