cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Invoice header and item Table

Former Member
0 Kudos

hello pals,

Please can someone show me how to update OINV and INV1 respectively through code.am developing an Add-on which will update this two tables and the OINV table get updated correctly but the INV1 tables does not but rather insert new records.

Accepted Solutions (0)

Answers (2)

Answers (2)

edy_simon
Active Contributor
0 Kudos

Hi Annie,

SInce you are not familiar with sdk yet,

i suggest you make yourself comfortable first by removing the loop and try to hardcode everything.

this code is to update the first line

oInvoice.Lines.SetCurrentLine(0)

oInvoice.Lines.ItemCode = 'AnyItemCodeHere'

oInvoice.Update

check your invoice....

if your invoice has 3 lines. Use this to update the last line.

oInvoice.Lines.SetCurrentLine(2)

oInvoice.Lines.ItemCode = 'AnyItemCodeHere'

oInvoice.Update

check your invoice....


Use this to add a new line

oInvoice.Lines.Add

oInvoice.Lines.ItemCode = 'AnyItemCodeHere'

oInvoice.Lines.Quantity =1

oInvoice.Update

check your invoice....



Regards,

edy

Former Member
0 Kudos

Hi Edy,

         The data am inserting is in array in and can't do without the loop.

edy_simon
Active Contributor
0 Kudos

Hi Annie,

I am not asking you to change your array.

What i am trying to tell you is .

Test and observe what and how SDK Object is handling things.

Once you are familiar with it, implement it in your array looping.

Regards

Edy

edy_simon
Active Contributor
0 Kudos

Hi Annie,

To update a specific line of document, you need to query the document first and look for the VisOrder field.

The use this method to call the line you need to update, passing the VisOrder you have got from the query.

oDocs.Lines.SetCurrentLine(iVisOrder);

..Update all your data here.

Then execute the update function,

oDocs.Update();

Regards

Edy

Former Member
0 Kudos

Hello Edy,

Have done as you said but is still inserting instead of updating.below is the code for doing the update.

  If oInvoice.GetByKey(lngDocEntry) = True Then

                oInvoice.CardCode = strCardCode

                oInvoice.DocTotal = DocTotalvalue

                For Each classItems As DraftClass In itemsData

                    oInvoice.Lines.ItemCode = classItems.itemCode

                    oInvoice.Lines.Price = classItems.PriceBefDi

                    oInvoice.Lines.PriceAfterVAT = classItems.PriceAfVat

                    oInvoice.Lines.LineTotal = classItems.LineTotal

                    oInvoice.Lines.GrossBuyPrice = classItems.GrossProfit

                    oInvoice.Lines.SetCurrentLine(classItems.VisOrder)

                    oInvoice.Lines.Add()

                Next

                lRetCode = oInvoice.Update()

                If lRetCode <> 0 Then

                    oCompany.GetLastError(lErrcode, sErrMsg)

                    SBO_Application.MessageBox(lErrcode & " " & sErrMsg, 1, "", "", "")

                Else

                    RetvalInoviceId = oCompany.GetNewObjectKey()

                End If

            End If

Former Member
0 Kudos


Hello Edy,


thanks because is now updating.

edy_simon
Active Contributor
0 Kudos

Hi Annie,

Can you help to close this thread if you have got your answer.

regards,

edy

Former Member
0 Kudos

hello Edy,

   Thanks but am witnessing an issue after the update.i realize the last record in line items does not get updated although am using Visorder to do the update

edy_simon
Active Contributor
0 Kudos

Hi Annie,

Can you post you latest code here ?

Regards

Edy

Former Member
0 Kudos

  For Each classItems As DraftClass In itemsData

                    oInvoice.Lines.ItemCode = classItems.itemCode

                    oInvoice.Lines.Price = classItems.PriceBefDi

                    oInvoice.Lines.PriceAfterVAT = classItems.PriceAfVat

                    oInvoice.Lines.LineTotal = classItems.LineTotal

                    oInvoice.Lines.GrossBuyPrice = classItems.GrossProfit

                    oInvoice.Lines.Add()

                    oInvoice.Lines.SetCurrentLine(classItems.VisOrder)

                 

                Next

                lRetCode = oInvoice.Update()

edy_simon
Active Contributor
0 Kudos

Hi Annie,

For Each classItems As DraftClass In itemsData

                    oInvoice.Lines.SetCurrentLine(classItems.VisOrder)     '<-- Before update, set the line first

                    oInvoice.Lines.ItemCode = classItems.itemCode

                    oInvoice.Lines.Price = classItems.PriceBefDi

                    oInvoice.Lines.PriceAfterVAT = classItems.PriceAfVat

                    oInvoice.Lines.LineTotal = classItems.LineTotal

                    oInvoice.Lines.GrossBuyPrice = classItems.GrossProfit

                    'oInvoice.Lines.Add()     <--- updating line, no need to add, unless you want to add a new line

                

                Next

                lRetCode = oInvoice.Update()

Regards
Edy

Former Member
0 Kudos

hi edy,

                   oInvoice.Lines.SetCurrentLine(classItems.VisOrder)

                    oInvoice.Lines.ItemCode = classItems.itemCode

                    oInvoice.Lines.Price = classItems.PriceBefDi

                    oInvoice.Lines.PriceAfterVAT = classItems.PriceAfVat

                    oInvoice.Lines.LineTotal = classItems.LineTotal

                    oInvoice.Lines.GrossBuyPrice = classItems.GrossProfit

with the above code the items does not get updated at all when i move the

   oInvoice.Lines.SetCurrentLine(classItems.VisOrder) at bottom it updates but leaves the last record out.

edy_simon
Active Contributor
0 Kudos

Hi Annie,

before you update, how many line was in the draft?

and you are upadating existing line only or adding a new line also?

set current line has to go first.

regards,

edy.

Former Member
0 Kudos

hi Edy,

  The lines in the draft to be updated is 4 and yes am updating existing records only.

first three lines gets updated but the 4th one does not.