cancel
Showing results for 
Search instead for 
Did you mean: 

UoMEntry Exception.

0 Kudos
138

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 :

"Attempted to read or write protected memory. This is often an indication that other memory has been corrupted".

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member369006
Participant
0 Kudos

Hi

Can I see your code?

Regards

Pawel

0 Kudos

Hi

its just :

vInvoice.Lines.UoMEntry = 1

that gives me that exception error.

Regards, Boughli

former_member183373
Active Participant
0 Kudos

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

former_member369006
Participant
0 Kudos

Is there an entry in OUOM table where UoMEntry=1 ?

0 Kudos

already done that.

regards, Boughli

0 Kudos

yep there is an entry called "UNIT" with the "UoMEntry = 1".

regards, Boughli

former_member183373
Active Participant
0 Kudos

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

0 Kudos

        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

former_member183373
Active Participant
0 Kudos

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.

0 Kudos

" vInvoice.Lines.UoMEntry = 1" and "vInvoice.Lines.UoMEntry = DetailTicket.Item(9)" they both give the same error.

edy_simon
Active Contributor
0 Kudos

Hi,

I would suggest you try to re install your DI API.

And/or test your code in the latest version of SBO.

Just to ruled out that it is not a problem with your DI API problem /SBO version bug.

Regards

Edy