cancel
Showing results for 
Search instead for 
Did you mean: 

8.8 Invoice based on Order

Former Member
0 Kudos

Hi all,

I am trying to create an invoice based on a sales order.

I have this code which worked fine in SBO 2007 but now in 8.8 I get -2010 : Internal error

oDoc = (SAPbobsCOM.Documents) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
oDoc.CardCode = sCardcode;
oDoc.Lines.BaseType = 17;
oDoc.Lines.BaseEntry = int.Parse(docentry);
oDoc.Lines.BaseLine = 0;

Can anyone help me with this?

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

I have the same problem. Order -> Invoice works in 2007, but in 8.8 not. For me it occures when there is a modification in the order. If I just use a plain order (not modified) it works fine for me. Did you get any solution?

Szilard Pal

Former Member
0 Kudos

Hi Gordon,

It is a variable, but that is not the issue I think.

But just in case: here is the complete code

oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

try
{
	SAPbobsCOM.Documents oDoc = (SAPbobsCOM.Documents) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
	
	Matrix matrix = Matrix.GetFromUID(pVal.Form, "10");
	
	int rowcount = matrix.Rows.Count;
	string prev_docnum = "";
	string docnum = "";
	string docentry = "";
	string cardcode = "";
	int retval = 0;
	
	for(int i = 0;i <= rowcount-1;i++)
	{
		docnum = matrix.GetValue("11", i);
		cardcode = matrix.GetValue("10", i);
		string regel = matrix.GetValue("12", i);
		string itemcode = matrix.GetValue("8", i);
		
		if(prev_docnum != docnum)
		{
			if(prev_docnum != "")
			{
				retval = oDoc.Add();
				
				if(retval != 0)
				{
					int errcode;
					string errmsg;
					oCompany.GetLastError(out errcode, out errmsg);
					
					StatusBar.WriteError(String.Format("Fout bij verkooporder {0} - {1}: [{2}] {3}",
						docnum,
						cardcode,
						errcode.ToString(),
						errmsg));
				}
				else
				{
					string newdoc;
					oCompany.GetNewObjectCode(out newdoc);
					
					SAPbobsCOM.Recordset oRs = (SAPbobsCOM.Recordset) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
					try
					{
						oRs.DoQuery(String.Format("SELECT DocNum, convert(varchar(8),DocDate,112), CardName FROM OINV WHERE DocEntry = '{0}'", newdoc));
					
						StatusBar.WriteSucess(String.Format("Nieuwe factuur aangemaakt: {0} - {1}",
							oRs.Fields.Item(0).Value.ToString(),
							oRs.Fields.Item(2).Value.ToString()));
					}
					finally
					{
						System.Runtime.InteropServices.Marshal.ReleaseComObject(oRs);
						oRs = null;
						GC.Collect();
					}
				}
				
				oDoc = null;
				oDoc = (SAPbobsCOM.Documents) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
			}
			
			// GET DOCENTRY
			SAPbobsCOM.Recordset oRsDoc = (SAPbobsCOM.Recordset) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
			try
			{
				oRsDoc.DoQuery(String.Format("SELECT DocEntry FROM ORDR WHERE DocNum = '{0}'", docnum));
				docentry = oRsDoc.Fields.Item(0).Value.ToString();
			}
			finally
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(oRsDoc);
				oRsDoc = null;
				GC.Collect();
			}
			
			oDoc.CardCode = cardcode;
			oDoc.DocDate = DateTime.Now;
		}
		
		oDoc.Lines.BaseType = 17;
		oDoc.Lines.BaseEntry = int.Parse(docentry);
		oDoc.Lines.BaseLine = int.Parse(regel) - 1;
		oDoc.Lines.Add();
		oDoc.Lines.SetCurrentLine(int.Parse(regel) - 1);
		
		prev_docnum = docnum;
	}
	
	// ADD LAST INVOICE
	retval = oDoc.Add();
	if(retval != 0)
	{
		int errcode;
		string errmsg;
		oCompany.GetLastError(out errcode, out errmsg);
					
		StatusBar.WriteError(String.Format("Fout bij verkooporder {0} - {1}: [{2}] {3}",
			docnum,
			cardcode,
			errcode.ToString(),
			errmsg));
	}
	else
	{
		string newdoc;
		oCompany.GetNewObjectCode(out newdoc);
					
		SAPbobsCOM.Recordset oRs = (SAPbobsCOM.Recordset) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
		try
		{
			oRs.DoQuery(String.Format("SELECT DocNum, convert(varchar(8),DocDate,112), CardName FROM OINV WHERE DocEntry = '{0}'", newdoc));
					
			StatusBar.WriteSucess(String.Format("Nieuwe factuur aangemaakt: {0} - {1}",
				oRs.Fields.Item(0).Value.ToString(),
				oRs.Fields.Item(2).Value.ToString()));
		}
		finally
		{
			System.Runtime.InteropServices.Marshal.ReleaseComObject(oRs);
			oRs = null;
			GC.Collect();
		}
	}
				
	oDoc = null;
}
catch(Exception ex)
{
	StatusBar.WriteError(ex.Message);
}

Former Member
0 Kudos

Hey Joeri,

(How are you:-) )

If the value of regel = 0 this statement is not correct :

oDoc.Lines.BaseLine = int.Parse(regel) - 1;

Because

oDoc.Lines.BaseLine = - 1;

is not correct.

If this is not the error please tell us where this error occured.

HTH Regards Teun

Former Member
0 Kudos

Hi Gordon,

Thanks for the quick reply...

The small section of code I typed sits in a larger code block.

The variable "docentry" is set for every new found sales order in a grid

Basically what I am trying to do is to capture the "Delivery" button on the pick and pack manager and create not a delivery but an invoice...

Kind regards,

Joeri

Former Member
0 Kudos

If it is small section of code, the linenum should also be a variable unless you have only one line.

Former Member
0 Kudos

Hi,

How do you get Sales Order docentry from this line: oDoc.Lines.BaseEntry = int.Parse(docentry);?

Thanks,

Gordon