Number sequence issue with General Journal

Hi ,

I have a form and which has all the fields for journal entry. It has a button “Transfer to Journal”. In the Click method of that button , i have written the following code:

void clicked()

{

LedgerJournalName LedgerJournalName;

ProjTable ProjTable;

RecordInsertList recordInsertList = new RecordInsertList(tableNum(LedgerJournalTrans));

RecordInsertList recordInsertList1 = new RecordInsertList(tableNum(LedgerJournalTrans_Project));

RecordInsertList recordInsertList2 = new RecordInsertList(tableNum(LedgerJournalTable));

LedgerJournalTable jourTable;

LedgerJournalTrans jourTrans;

LedgerJournalNameId LedgerJournalNameId= ‘Effort’;

LedgerJournalTrans_Project LedgerJournalTrans_Project;

LedgerJournalTableData jourTableData;

LedgerJournalTransData jourTransData;

LedgerJournalStatic jourStatic;

UploadFile UploadFileLoc;

NumberSeq numberSeq;

boolean flag=true;

;

ttsbegin;

breakpoint;

ledgerJournalEngine = new LedgerJournalEngine();

select firstonly LedgerJournalName where LedgerJournalName.JournalName ==LedgerJournalNameId;

jourTableData = JournalTableData::newTable(jourTable);

jourTable.JournalNum = jourTableData.nextJournalId();

// jourTable.JournalType = LedgerJournalType::

jourTable.Name = ‘Effort’;

jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.Name));

jourStatic = jourTableData.journalStatic();

jourTable.insert();

// jourTable.clear();

//

// select LedgerJournalName where LedgerJournalName.JournalName == LedgerJournalNameId;

// if(!LedgerJournalName)

// error(‘Journal Not found’);

// jourTable.Name=‘Effort’;

// jourTable.initFromLedgerJournalName(LedgerJournalNameId);

// jourTable.JournalNum = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();

// jourTable.insert();

while select UploadFileLoc

where UploadFileLoc.Selection == NoYes::Yes

{

breakpoint;

jourTransData = jourStatic.newJournalTransData(jourTrans,jourTableData);

jourTransData.initFromJournalTable();

jourTrans.initValue();

jourTrans.CurrencyCode = UploadFileLoc.UploadCurrency;

jourTrans.validateField(fieldnum(LedgerJournalTrans, CurrencyCode));

jourTrans.TransDate = UploadFileLoc.Date;

jourTrans.AccountType= UploadFileLoc.AccountPlType;

jourTrans.validateField(fieldnum(LedgerJournalTrans, AccountType));

jourTrans.AccountNum = UploadFileLoc.AccountNum;

jourTrans.validateField(fieldnum(LedgerJournalTrans, AccountNum));

jourTrans.OffsetAccountType=UploadFileLoc.OffsetAccountType;

jourTrans.validateField(fieldnum(LedgerJournalTrans, OffsetAccountType));

jourTrans.OffsetAccount = UploadFileLoc.OffsetAccount;

jourTrans.validateField(fieldnum(LedgerJournalTrans, OffsetAccount));

jourTrans.AmountCurDebit=UploadFileLoc.AmountCurDebit;

jourTrans.validateField(fieldnum(LedgerJournalTrans, AmountCurDebit));

jourTrans.AmountCurCredit =UploadFileLoc.AmountCurCredit;

jourTrans.validateField(fieldnum(LedgerJournalTrans, AmountCurCredit));

jourTrans.Txt=UploadFileLoc.Text;

jourTrans.ExchRate = Currency::exchRate(jourTrans.CurrencyCode);

jourTrans.validateField(fieldnum(LedgerJournalTrans, ExchRate));

jourTrans.Dimension[1]=UploadFileLoc.Dimension[1];

jourTrans.Dimension[2]=UploadFileLoc.Dimension[2];

jourTrans.Dimension[4]=UploadFileLoc.Dimension[4];

jourTrans.Dimension[6]=UploadFileLoc.Dimension[6];

jourTrans.Dimension[8]=UploadFileLoc.Dimension[8];

numberseq =NumberSeq::newGetVoucherFromCode(LedgerJournalName.VoucherSeries);

jourTrans.Voucher = numberseq.voucher();

ledgerJournalEngine.amountCurDebitModified(jourTrans);

ledgerJournalEngine.clearTaxAmountCache(jourTrans);

ledgerJournalEngine.cashDiscCodeModified(jourTrans);

jourTrans.modifiedField(fieldnum (LedgerJournalTrans,AmountCurDebit));

if(UploadFileLoc.AccountPlType==LedgerJournalACType::Project)

{

breakpoint;

LedgerJournalTrans_Project.CategoryId=UploadFileLoc.CategoryId;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, CategoryId));

LedgerJournalTrans_Project.LinePropertyId=UploadFileLoc.LinePropertyId;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, LinePropertyId));

LedgerJournalTrans_Project.EmplId=UploadFileLoc.EmplId;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project,EmplId));

LedgerJournalTrans_Project.SalesCurrencyId=UploadFileLoc.UploadCurrency;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project,SalesCurrencyId));

LedgerJournalTrans_Project.SalesPrice=UploadFileLoc.SalesPrice;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project,SalesPrice));

LedgerJournalTrans_Project.CostPrice=UploadFileLoc.CostPrice;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project,CostPrice));

LedgerJournalTrans_Project.Qty=UploadFileLoc.Quantity;

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project,Qty));

LedgerJournalTrans_Project.RefRecId=jourTrans.RecId;

recordInsertList1.add(LedgerJournalTrans_Project);

LedgerJournalTrans_Project = null;

// LedgerJournalTrans_Project.insert();

}

// else

// {

// flag=false;

// throw error(“Validation failed for Project Type.Please fill mandatory fileds”);

//

// }

if (jourTrans.validateField(fieldnum(LedgerJournalTrans, CurrencyCode)) &&

jourTrans.validateField(fieldnum(LedgerJournalTrans, AccountNum)) &&

jourTrans.validateField(fieldnum(LedgerJournalTrans, AccountType))&&

jourTrans.validateField(fieldnum(LedgerJournalTrans, OffsetAccount))&&

jourTrans.validateField(fieldnum(LedgerJournalTrans, OffsetAccountType)) &&

jourTrans.validateField(fieldnum(LedgerJournalTrans, AmountCurDebit)) &&

jourTrans.validateField(fieldnum(LedgerJournalTrans, AmountCurCredit))&&

jourTrans.validateField(fieldnum(LedgerJournalTrans, ExchRate) ))

{

if(UploadFileLoc.AccountPlType!=LedgerJournalACType::Project || (UploadFileLoc.AccountPlType==LedgerJournalACType::Project &&

(LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, CategoryId)) &&

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, LinePropertyId)) &&

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, SalesCurrencyId)) &&

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, SalesPrice)) &&

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, CostPrice)) &&

LedgerJournalTrans_Project.validateField(fieldnum(LedgerJournalTrans_Project, Qty)))))

{

// jourTrans.insert();

recordInsertList.add(jourTrans);

jourTrans = null;

// recordInsertList2.add(jourTable);

// jourTable=null;

}

else

{

flag=false;

throw error(“Validation failed for Project Type.Please fill mandatory fileds”);

}

}

else

{

flag=false;

throw error(“Validation failed”);

}

UploadFileLoc.selectForUpdate(true);

UploadFileLoc.delete();

info(strfmt(‘Journal Id:%1’,jourTable.JournalNum));

}

if(flag)

{

if(recordInsertList1.usageCount() > 0)

{

recordInsertList1.insertDatabase();

}

if(recordInsertList.usageCount() > 0)

{

recordInsertList.insertDatabase();

}

// if(recordInsertList2.usageCount() >0)

// {

//

// recordInsertList2.insertDatabase();

//

//

// }

}

else

{

info(strfmt(‘Journal Id:%1 creation failed. Please find the above error messages for failure’,jourTable.JournalNum));

}

ttscommit;

UploadFile_ds.refresh();

UploadFile_ds.reread();

UploadFile_ds.research();

}

All the validations are going correctly. However i have one issue. Even if the validation fails saying the category id is not correct, a Journal id is created. However when i check the journal table, the id doesnot exist. So i want to ensure that no journal id is creaed when the validation fails . It should only be created when the validation completely pass.

Code for LedgerJournalTableData which you see above in the code is as follows:

void create( boolean _doInsert = false, boolean _initVoucherList = true)

{

;

lastLineNum++;

journalTrans.LineNum = lastLineNum;

if (journalTableData.journalVoucherNum())

{

this.initVoucher( lastVoucher, false, _initVoucherList);

}

this.addTotal(false, false);

if (_doInsert)

{

journalTrans.doInsert();

}

else

{

journalTrans.insert();

}

if (journalTableData.journalVoucherNum())

{

lastVoucher = journalTrans.Voucher;

}

}

Can anyone please help me quickly

Regards,
Saurav

any help guys…