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
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 ");
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156