Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Journal control Import

Posted on by Microsoft Employee

Any body help to import data in journal control against journal names in Ax 2012.

Thanks in Advance.

Mythili Sundar

*This post is locked for comments

  • Suggested answer
    Jeevanandham Profile Picture
    Jeevanandham 30 on at
    RE: Journal control Import

    static void uploadJournalControl(Args _args)
    {
    SysExcelApplication xlsApplication;
    SysExcelWorkBooks xlsWorkBookCollection;
    SysExcelWorkBook xlsWorkBook;
    SysExcelWorksheets xlsWorkSheetCollection;
    SysExcelWorksheet xlsWorkSheet;
    SysExcelRange xlsRange;
    SysExcelCells Cells;
    SysExcelCell RCell;
    COMVariantType type;
    CommaIO inFile;
    int nRow,i;

    DialogField dialogPath;
    Dialog dialog;
    Filename filename;

    RefRecId dataAreaId;
    LedgerJournalNameId id;

    LedgerJournalControlHeader header;
    TmpLedgerJournalControlDetail tmp;
    LedgerJournalControlForm ledgerJournalControlForm;

    dialog = new Dialog("Import");
    dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
    dialog.run();

    if (dialog.run())
    {
    filename = (dialogPath.value());
    }

    inFile = new CommaIO (filename, 'R');

    if (!inFile || infile.status() != IO_Status::Ok )
    {
    throw error (strfmt("@SYS19312",filename));
    }

    try
    {
    xlsApplication = SysExcelApplication::construct();
    xlsWorkBookCollection = xlsApplication.workbooks();
    xlsWorkBookCollection.open(filename);
    xlsWorkSheetCollection = xlsApplication.worksheets();
    xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
    Cells = xlsWorkSheet.Cells();
    nRow = 2;
    //RCell = Cells.Item(nRow, 1);
    info(strFmt("Starts at : %1 %2", systemDateGet(), time2StrHMS(timeNow())));

    while (Cells.Item(nRow, 1).value().bStr() != "")
    {
    ttsBegin;
    id = Cells.Item(nRow, 1).value().bStr();
    dataAreaId = CompanyInfo::findDataArea(Cells.Item(nRow, 2).value().bStr()).RecId;

    header = LedgerJournalControlHeader::findByJournalNameCompanyAccountType(id, dataAreaId, LedgerJournalACTypeAll::Ledger);

    if (!header)
    {
    header.clear();
    header.AccountType = LedgerJournalACTypeAll::Ledger;
    header.JournalLegalEntity = dataAreaId;
    header.JournalName = id;
    header.insert();
    }

    ledgerJournalControlForm = LedgerJournalControlForm::construct(header.RecId, tmp);

    tmp.clear();
    tmp.LedgerLegalEntity = header.JournalLegalEntity;
    tmp.DimensionHierarchy = DimensionHierarchy::findByTypeAndName(DimensionHierarchyType::AccountStructure, Cells.Item(nRow, 4).value().bStr()).RecId;
    tmp.DimensionAttribute = DimensionAttribute::findByName(Cells.Item(nRow, 5).value().bStr()).RecId;
    tmp.DimensionConstraintTree = 0;
    tmp.LedgerJournalControlDetail = 0;
    tmp.RangeFrom = Cells.Item(nRow, 6).value().bStr();
    tmp.RangeTo = Cells.Item(nRow, 7).value().bStr();
    tmp.insert();

    ledgerJournalControlForm.processTempDetail(tmp);
    ttsCommit;

    nRow++;
    }

    xlsApplication.quit ();
    xlsApplication.finalize ();
    info("Import completed");
    info(strFmt("Ends at : %1 %2", systemDateGet(), time2StrHMS(timeNow())));
    }
    catch( Exception::Error)
    {
    info(strFmt("Error in line number %1", nRow + 1));
    xlsApplication.quit ();
    xlsApplication.finalize ();
    ttsabort;
    info("Unable to process the excel import ");
    }
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans