Hi
I have created an import tool (got the code from a nice blogger, Thanks!) and changed it slightly to suit my needs, the import woks fine bu the journal cannot be posted.
I get this error: Cannot create a record in Hours (ProjEmplTrans). Project: P00007, 2010-09-09.
The record already exists.
Which offcourse is not true, at least not in that table this record does not exsit. I suspect my number sequence assignment might be wrong. Any tip would be great.
Here’s the code:
``
public void InsertProjHours()
{
#define.ioComma(";")
#define.ioEndLine("\r\n")
#define.ioRead("r")
`
AsciiIo io ;
real TotalHours;
str jourName;
str 10 jourNum;
str lineNum;
str projectId;
str costprice;
str salesprice;
str lineprop;
str category;
str salescurrency;
str empl;
str qty;
str transdate;
str projtransdate;
str businessline;
str costcenter;
str transtxt;
str fileName;
int linecount;
ProjJournalTrans projJournalTrans;
ProjJournalTable projJournalTable;
LedgerJournalACType ledgerJournalACType;
NumberSeq numSeq;
NumberSeq numSeqJour;
int n = 1,idx =1;
SysOperationProgress lprogress;
#AviFiles
;
fileName = StringEditFileName.valueStr();
jourName = ComboBoxJournalName.valueStr();
io = new AsciiIo(fileName, #ioRead);
if(!io)
error (“File cannot be open”);
lprogress = new SysOperationProgress();
lprogress.setCaption("Insert General ledger trans ");
lprogress.setAnimation(#AviUpdate);
//Create the journal
numseqJour = NumberSeq::newGetNumFromCode(ProjParameters::numRefProjJournalId().NumberSequence);
projJournalTable.initFromProjJournalName(ProjJournalName::Find(jourName));
journum = numseqJour.num();
projJournalTable.JournalNameId = jourName;
projJournalTable.Description = ProjJournalName::Find(jourName).Description;
projJournalTable.VoucherSeqId = ProjJournalName::Find(jourName).VoucherSeqId;
projJournalTable.JournalId = journum;
projJournalTable.insert();
//Create lines
if (io)
{
io.inFieldDelimiter(#ioComma);
io.inRecordDelimiter(#ioEndLine);
[projtransdate, salescurrency, costprice, projectid, salesprice ,qty, transtxt, businessline, costcenter, lineprop, category, empl] = io.read();
while (io.status() == IO_Status::Ok)
{
if (io.status() != IO_Status::Ok)
{
error(“File not found”);
}
TotalHours += str2Num(qty);
ttsbegin;
lprogress.setCount(n,Idx);
lprogress.setText(“Inserting trans”);
n++;
Idx++;
numSeq = NumberSeq::newGetVoucherFromCode(ProjJournalName::find(jourName).VoucherSeqId);
if(!numSeq)
{
error(strfmt(“Number sequence set up does not exists for journal %1”,jourName));
break;
}
projJournalTrans.Voucher = numSeq.voucher();
numSeq.used();
projJournalTrans.TransDate = Today();
projJournalTrans.ProjTransDate = str2date(projtransdate, 321);
projJournalTrans.JournalId = jourNum;
projJournalTrans.LineNum = str2num(lineNum);
projJournalTrans.CostPrice = str2num(costprice);
projJournalTrans.SalesPrice = str2num(salesprice);
projJournalTrans.EmplId = empl;
projJournalTrans.LinePropertyId = lineprop;
projJournalTrans.CategoryId = category;
projJournalTrans.txt = transtxt;
projJournalTrans.CurrencyId = salescurrency;
projJournalTrans.Dimension[1] = businessline;
projJournalTrans.Dimension[2] = costcenter;
projJournalTrans.ProjId = projectid;
projJournalTrans.Dimension[4] = projectid;
projJournalTrans.Qty = str2num(qty);
projJournalTrans.insert();
ttscommit;
[projtransdate, salescurrency, costprice, projectid, salesprice ,qty, transtxt, businessline, costcenter, lineprop, category, empl] = io.read();
}
}
ttsbegin;
select firstonly forupdate projJournalTable where projJournalTable.JournalId == jourNum;
projJournalTable.NumOfLines = projJournalTrans.numOfLines();
projJournalTable.ProjQty = TotalHours;
projJournalTable.update();
ttscommit;
info(strFmt(“import complete: Imported %1 records. New Journal %2 created”, (n-1), journum));
element.close();
}
`