Import Excel Data into Standard Tables (LedgerJournalTables , LedgerJournalTrans)
1)First Create Records In Excel
JournalNum field Is aNumSeq--
we can find out
workspace>>GeneralLedger>>Setup>>GeneralLedgerParameters.(open)
RightClick On NumberSeqCode>>click on ViewDetails
we can see Format, and Next value
means in x-cel we can create JournalNum from392 onwords ex:INMF-00392
Then only it allows record otherwise record not insertd..
2)write code In Job:
static void ImportLedgerJournalData(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
// write the table names
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournaltrans;
FileName filename;
int i,col,row =1;
real AmountCurCredit;
int64 ledgerDimension;
str MarkedInvoice,Txt,journalnum,JournalName,Name,CurrencyCode;
date Transdate;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "D:\\CopyofImportLedgerJournal4.xlsx";
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
cells = worksheet.cells();
//row++;
do
{
ttsBegin;
row++;
AmountCurCredit = cells.item(row, 1).value().double();
journalnum = cells.item(row, 2).value().bStr();
ledgerDimension = cells.item(row, 3).value().int();
MarkedInvoice = cells.item(row, 4).value().bStr();
Txt = cells.item(row, 5).value().bStr();
Transdate = cells.item(row, 6).value().date();
Name = cells.item(row, 7).value().bStr();
JournalName = cells.item(row, 8).value().bStr();
CurrencyCode = cells.item(row, 9).value().bStr();
ledgerJournalTable.JournalNum = journalnum;
ledgerJournalTable.JournalName = JournalName;
ledgerJournalTable.Name = Name;
ledgerJournalTable.CurrencyCode = CurrencyCode;
ledgerJournalTable.insert();
ledgerJournaltrans.JournalNum = journalnum;
ledgerJournaltrans.AmountCurCredit = AmountCurCredit;
ledgerJournaltrans.ledgerDimension = ledgerDimension;
ledgerJournaltrans.Txt = Txt;
ledgerJournaltrans.MarkedInvoice = MarkedInvoice;
ledgerJournaltrans.Transdate = Transdate;
ledgerJournaltrans.CurrencyCode = CurrencyCode;
ledgerJournaltrans.insert();
ttsCommit;
i++;
type = cells.item(row+1, 1).value().variantType();
}
while(type != COMVariantType::VT_EMPTY);
application.quit();
info("Import is done");
}
output:Search In Bothtables Data is inserted or not........
1)First Create Records In Excel
JournalNum field Is aNumSeq--
we can find out
workspace>>GeneralLedger>>Setup>>GeneralLedgerParameters.(open)
RightClick On NumberSeqCode>>click on ViewDetails
we can see Format, and Next value
means in x-cel we can create JournalNum from392 onwords ex:INMF-00392
Then only it allows record otherwise record not insertd..
2)write code In Job:
static void ImportLedgerJournalData(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
// write the table names
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournaltrans;
FileName filename;
int i,col,row =1;
real AmountCurCredit;
int64 ledgerDimension;
str MarkedInvoice,Txt,journalnum,JournalName,Name,CurrencyCode;
date Transdate;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "D:\\CopyofImportLedgerJournal4.xlsx";
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
cells = worksheet.cells();
//row++;
do
{
ttsBegin;
row++;
AmountCurCredit = cells.item(row, 1).value().double();
journalnum = cells.item(row, 2).value().bStr();
ledgerDimension = cells.item(row, 3).value().int();
MarkedInvoice = cells.item(row, 4).value().bStr();
Txt = cells.item(row, 5).value().bStr();
Transdate = cells.item(row, 6).value().date();
Name = cells.item(row, 7).value().bStr();
JournalName = cells.item(row, 8).value().bStr();
CurrencyCode = cells.item(row, 9).value().bStr();
ledgerJournalTable.JournalNum = journalnum;
ledgerJournalTable.JournalName = JournalName;
ledgerJournalTable.Name = Name;
ledgerJournalTable.CurrencyCode = CurrencyCode;
ledgerJournalTable.insert();
ledgerJournaltrans.JournalNum = journalnum;
ledgerJournaltrans.AmountCurCredit = AmountCurCredit;
ledgerJournaltrans.ledgerDimension = ledgerDimension;
ledgerJournaltrans.Txt = Txt;
ledgerJournaltrans.MarkedInvoice = MarkedInvoice;
ledgerJournaltrans.Transdate = Transdate;
ledgerJournaltrans.CurrencyCode = CurrencyCode;
ledgerJournaltrans.insert();
ttsCommit;
i++;
type = cells.item(row+1, 1).value().variantType();
}
while(type != COMVariantType::VT_EMPTY);
application.quit();
info("Import is done");
}
output:Search In Bothtables Data is inserted or not........
Comments
Post a Comment