MYOBCommunity
Partner Zone
|
|
Partner Zone

Getting Invoice Number after Insert

This thread is now closed to new comments.
Some of the links provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
2 REPLIES 2
Contributing Partner entiretech
9 Posts
Contributing Partner
New Zealand
entiretech
Contributing Partner

9Posts

6Kudos

1Solutions

Re: Getting Invoice Number after Insert

Actually, there is one better way.  Instead of calling ItemInvoiceService.Insert() call ItemInvoiceService.InsertEx() as that will return you an ItemInvoice object which contains the GUID you're after as well.

 

For example:

 

'INSERT THE INVOICE
Dim objResult As ItemInvoice = objService.InsertEx(MYOBConfig.CompanyFile, objMYOBInvoice, MYOBConfig.Credentials)

'FIND THE INVOICE UID
Me.strUID = objResult.UID.ToString

 

(forgot I found a better way!) :-)

Contributing Partner entiretech
9 Posts
Contributing Partner
New Zealand
entiretech
Contributing Partner

9Posts

6Kudos

1Solutions

Accepted Solution Solved Solution

Re: Getting Invoice Number after Insert

There is probably a much better way than this but this was the best solution I could come up with at the moment:

 

''' <summary>
''' Finds the newly created invoice.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function FindNewlyCreatedInvoice(CustomerUID As Guid, MYOBConfig As Config) As ItemInvoice
Dim objService As ItemInvoiceService
Dim lstInvoices As PagedCollection(Of ItemInvoice)

If MYOBConfig.AccessMode = Config.EAccessMode.Cloud Then
objService = New ItemInvoiceService(MYOBConfig.APIConfig, , MYOBConfig)
Else
objService = New ItemInvoiceService(MYOBConfig.APIConfig)
End If

lstInvoices = objService.GetRange(MYOBConfig.CompanyFile, "$top=1&$orderby=Number desc&$filter=Customer/UID eq guid'" & CustomerUID.ToString & "'", MYOBConfig.Credentials)

If lstInvoices.Count >= 1 Then
Return lstInvoices.Items(0)
Else
Return Nothing
End If
End Function

 

The only issue is that if an invoice is created between you insert the invoice in your code and then running this function it will give you the wrong invoice.

 

This code only works with item invoice types :-)

Highlighted
Partner 365Software
1 Post
Partner
365Software

1Posts

0Kudos

0Solutions

Solved: Go to Solution

Getting Invoice Number after Insert

I am using the API via VB.net to successfully generate a new Item Invoice using MYOB.AccountRight.SDK.Services.Sale.ItemInvoiceService

 

We are not passing the object a Invoice Number as we are using MYOB auto generated numbering. 

 

My question is, after calling the itemInvoiceSvc.Insert(_companyFiles(0), itemInvoice, credentials)

which is working and itemInvoice is the object sent, how do we get the Invoice Number that is being generated? I was thinking the itemInvoice object would contain it after the Insert but it doesn't..

Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post