Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Adding JournalEntry

Hi everyone,

im trying to add new JournalEntry but i always get an error about the primary key.

I see that it doesnt change the Line_ID from 0 to 1.

Here is my code...

SAPbobsCOM.JournalEntries journalEntries = (SAPbobsCOM.JournalEntries)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries);

oCompany.StartTransaction();

foreach( DataRow dr in sqlDT.Rows )

{

journalEntries.TaxDate = DateTime.Now;

journalEntries.Lines.AccountCode = ShortName;

journalEntries.Lines.ContraAccount = DestShortName;

journalEntries.Lines.Credit = Convert.ToInt32( dr["Credit"] );

journalEntries.Lines.Debit = Convert.ToInt32( dr["Debit"] );

journalEntries.Lines.DueDate = DateTime.Parse( dr["DueDate"].ToString() );

journalEntries.Lines.ReferenceDate1 = DateTime.Now;

journalEntries.Lines.ShortName = ShortName;

journalEntries.Lines.TaxDate = DateTime.Now;

journalEntries.Lines.Add();

journalEntries.Lines.SetCurrentLine(1);

journalEntries.Lines.AccountCode = DestShortName;

journalEntries.Lines.ContraAccount = ShortName;

journalEntries.Lines.Credit = Convert.ToInt32( dr["Debit"] );

journalEntries.Lines.Debit = Convert.ToInt32( dr["Credit"] );

journalEntries.Lines.DueDate = DateTime.Parse( dr["DueDate"].ToString() );

journalEntries.Lines.ReferenceDate1 = DateTime.Now;

journalEntries.Lines.ShortName = DestShortName;

journalEntries.Lines.TaxDate = DateTime.Now;

if (!journalEntries.Add().Equals(0))

{

oCompany.GetLastError(out errCode, out errMsg);

if (!errCode.Equals(0))

{

clsBase.Application.MessageBox("Error: " + errMsg, 0, "OK", null, null);

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);

}

else

{

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

clsBase.Application.MessageBox("...", 0, "OK", null, null);

}

clsBase.Application.MessageBox("...", 0, "OK", null, null);

return;

}

}

oCompany.GetLastError( out errCode, out errMsg);

if (!errCode.Equals(0))

{

clsBase.Application.MessageBox("Error: " + errMsg, 0, "OK", null, null);

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);

}

else

{

oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

clsBase.Application.MessageBox("...", 0, "OK", null, null);

}

oCompany.Disconnect();

all the datarows and the variables have valid data that matches the type of field

please help

thanks

Ronen

Former Member
replied

Can you add a journalentry through SBO?

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question