web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Import Budget Transaction Lines without main account

(0) ShareShare
ReportReport
Posted on by 685

hi,

I created a job to import budget transaction lines, the line dimension values contains only dimensions without Main account ID; below is my code:

bbudgetTransactionLine = new AxBudgetTransactionLine();
                     bbudgetTransactionLine.parmBudgetTransactionHeader(BudgetTransactionHeader::findByTransactionNumber(Transaction_TransactionNumber.text(),Ledger::current()).RecId);
                     bbudgetTransactionLine.parmDate(str2Date(conPeek(readCon,6),123));
                     bbudgetTransactionLine.parmTransactionCurrency(conPeek(readCon,8));
                     bbudgetTransactionLine.parmBudgetType();
                     bbudgetTransactionLine.parmTransactionCurrencyAmount(str2num(conPeek(readCon,12)));
                     bbudgetTransactionLine.parmAccountingCurrencyAmount(str2num(conPeek(readCon,12)));
                     accEntryPattern = [strFmt("%1-%2",conPeek(readCon,9),conPeek(readCon,10)),0];
                         if(conPeek(readCon,9))
                         {
                           accEntryPattern += "Budget";
                           accEntryPattern += conPeek(readCon,9);
                           dimcount++;
                         }
                         if(conPeek(readCon,10))
                         {
                           accEntryPattern += "BUDGETYEAR";
                           accEntryPattern += conPeek(readCon,10);
                           dimcount++;
                         }

                     accEntryPattern = conIns(accEntryPattern,3,dimcount);
                     bbudgetTransactionLine.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accEntryPattern));
                     bbudgetTransactionLine.save();

when running the code the following error occurs:

"The main account 0 does not exist".

the issue is that the main account cannot be empty or have 0 as a value. how can i pass the parameter for parmLedgerDimension function in the BudgetTransactionline class.

any suggestion will be highly appreciated!

thank you.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Serge Abi Dib Profile Picture
    685 on at

    it is solved by the below using parmBudget by getting the ledger id using AxdDimensionUtil::getBudgetAccountId function;

    void clicked()
    {
    
    
        TextIo                              csvFile;
        container                           readCon;
        counter                             icount,inserted;
    
        Dialog                              dialog;
        DialogField                         dfFileName;
        FileName                            fileName;
        Integer                             hh=0;
    
        AxBudgetTransactionLine             bbudgetTransactionLine;
        container                           accEntryPattern;
        Integer                             dimcount;
        /*container                           defDimensionCon;
        Struct                              struct = new Struct();
        DimensionDefault                    dimensionDefault;
    
        CurrencyExchangeHelper              currencyExchangeHelper;
        AmountMst                           amountMST;*/
        /*container                           defDimensionCon;
        Struct                              struct = new Struct();
        DimensionDefault                    dimensionDefault;*/
    
        ;
         super();
        #File
    
        dialog = new Dialog("Pick the file to import budget!");
        dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
        dialog.filenameLookupFilter(["All files", #AllFiles]);
    
        if (dialog.run())
        {
            filename =  dfFileName.value();
        }
    
        if (fileName)
        {
            csvFile = SysLicenseCodeReadFile::openFile(fileName,'r');
            if (!csvFile)
                throw error(strfmt("@SYS18678",fileName));
    
            csvFile.inFieldDelimiter(",");
            if (csvFile)
            {
                //icount++;
                readCon = csvFile.read();
    
                ttsbegin;
                while (csvFile.status() == IO_Status::OK)
                {
                    readCon = csvFile.read();
                    icount++;
                    if (readCon)
                    {
    
                         bbudgetTransactionLine = new AxBudgetTransactionLine();
                         bbudgetTransactionLine.parmBudgetTransactionHeader(BudgetTransactionHeader::findByTransactionNumber(Transaction_TransactionNumber.text(),Ledger::current()).RecId);
                         bbudgetTransactionLine.parmDate(str2Date(conPeek(readCon,6),123));
                         bbudgetTransactionLine.parmTransactionCurrency(conPeek(readCon,8));
                         bbudgetTransactionLine.parmBudgetType(BudgetType::Expense);
                         bbudgetTransactionLine.parmTransactionCurrencyAmount(str2num(conPeek(readCon,12)));
                         bbudgetTransactionLine.parmAccountingCurrencyAmount(str2num(conPeek(readCon,12)));
                        bbudgetTransactionLine.parmLineNumber(icount);
    
                         accEntryPattern = [strFmt("%1-%2",conPeek(readCon,9),conPeek(readCon,10)),'EXP'];
                             if(conPeek(readCon,9))
                             {
                               accEntryPattern += "Budget";
                               accEntryPattern += conPeek(readCon,9);
                               dimcount++;
                             }
                             if(conPeek(readCon,10))
                             {
                               accEntryPattern += "BUDGETYEAR";
                               accEntryPattern += conPeek(readCon,10);
                               dimcount++;
                             }
    
                         accEntryPattern = conIns(accEntryPattern,3,dimcount);
                         //bbudgetTransactionLine.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accEntryPattern));
                        bbudgetTransactionLine.parmLedgerDimension(AxdDimensionUtil::getBudgetAccountId(accEntryPattern));
                        
                         accEntryPattern = conDel(accEntryPattern,1,7);
                        dimcount=0;
    
    
                         bbudgetTransactionLine.save();
    
    
                    }
                }
                ttsCommit;
            }
        }
    }
    


    Regards,
    Serge

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans