on 2015 May 07 9:45 AM
Hello Experts,
So, I am trying to add an Invoice with a little app that a made, but when i try to specify the "UoMEntry" i get the following Error :
I managed to break it to the following Exception :
"NullReferenceException" -
"Object reference not set to an instance of an object."
please help me out here i need to finish this quickly.
Regards, Boughli.
Hi
Can I see your code?
Regards
Pawel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Boughli,
You should set your "vInvoice" object to a Company Document.
First connect to the company database you are working with and then write this code block.
vInvoice= (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
vInvoice.Lines.UoMEntry =1;
Regards,
Atilla
Hi Boughli,
This is working for me;
private SAPbobsCOM.Company oCompany;
private SAPbobsCOM.Documents oInv;
oCompany = new SAPbobsCOM.Company();
oCompany.Server = "****";
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012;
oCompany.CompanyDB = "****";
oCompany.UserName = "****";
oCompany.Password = "***";
oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
int ret = oCompany.Connect();
oInv =(SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
oInv.Lines.UoMEntry =1;
Could you share the rest of your code block?
Thanks,
Atilla
Dim vInvoice As SAPbobsCOM.Documents
For Each Ticket As DataRow In dt_Ticket.Rows
vInvoice = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
vInvoice.DocNum = sNumTicket
vInvoice.CardCode = CardCode
vInvoice.DocDate = DocDate
vInvoice.DocDueDate = DocDate
vInvoice.TaxDate = DocDate
If iSalarie <> -1 Then
vInvoice.DocumentsOwner = iSalarie
End If
vInvoice.SalesPersonCode = iSalesPersonCode
vInvoice.NumAtCard = sNumTicket
vInvoice.Comments = "Ticket Vente Magasin(" & Magasin & ") Numero : " & sNumTicket
Dim dt_DetailTicket As New DataTable
dt_DetailTicket = db_centrale.execute_select("SELECT [num_ticket] ,detailticket. [code_art] ,[quantite],[remise] " & _
" ,[ht] ,[tva],[cours_devi],(Article.taux_tva/100)+1,code_bar,Embalage from DetailTicket,Article where [num_ticket]='" & sNumTicket & "' and Article.code_art= detailticket.code_art ")
For Each DetailTicket As DataRow In dt_DetailTicket.Rows
vInvoice.Lines.ItemCode = DetailTicket.Item(1).ToString
vInvoice.Lines.Quantity = DetailTicket.Item(2)
vInvoice.Lines.UnitPrice = (((DetailTicket.Item(4) + DetailTicket.Item(3)) / DetailTicket.Item(2)) / DetailTicket.Item(7)) * CDec(DetailTicket.Item(6).ToString)
vInvoice.Lines.DiscountPercent = CDbl((DetailTicket.Item(3) / (DetailTicket.Item(3) + DetailTicket.Item(4))) * 100)
vInvoice.Lines.LineTotal = (DetailTicket.Item(4) / DetailTicket.Item(7)) * CDec(DetailTicket.Item(6).ToString)
vInvoice.Lines.BarCode = DetailTicket.Item(8)
If DetailTicket.Item(9) <> -1 Then
vInvoice.Lines.UoMEntry = DetailTicket.Item(9)
Else
vInvoice.Lines.UoMEntry = 1
End If
vInvoice.Lines.WarehouseCode = Magasin
vInvoice.Lines.Add()
Next
oCompany.StartTransaction()
Chek_add_vInvoice = vInvoice.Add
'Check the result
If Chek_add_vInvoice <> 0 Then
oCompany.GetLastError(ErrCode, errMsg)
List_erreur_sap.Add("Num Ticket : (" & sNumTicket & ") " & ErrCode & " : " & errMsg)
Try
oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
Catch ex As Exception
End Try
Your code looks fine. I tried using same function in my environment and didn't get any problem about UoMEntry. Just to make sure. Can you confirm that the error caused by " vInvoice.Lines.UoMEntry = 1" not "vInvoice.Lines.UoMEntry = DetailTicket.Item(9)"
You may try using Convert.ToInt64(DetailTicket.Item(9)) in case of that.
User | Count |
---|---|
90 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.