Returning a document number
After you get a Microsoft Dynamics GP document number, you might find that you do not need to use that number. Typically, you return an unused document number so the number can be used later with another document.
To return a document number, you use the DocumentRollback class. The DocumentRollback class enables you to build a list of document numbers. You use this list with the RollBackDocumentList method of GetNextDocNumbers class to return unused document numbers to Microsoft Dynamics GP.
The following steps show how to retrieve a collection of document numbers and how to return those numbers to Microsoft Dynamics GP. You will also see how to view the individual members of a DocumentRollback arraylist.
Create the connection string
To retrieve and return document numbers, you need a connection string that specifies the data server and the company database.
The following Visual Basic example shows how to create a connection string.
'Create a connection string that connects to the TWO database ' on the local computer Dim connectionString As String connectionString = "Data Source=localhost;Integrated Security=SSPI;" _ & "Persist Security Info=False;Initial Catalog=TWO;"
Get the document number
To retrieve a document number, use the GetNextDocNumbers class. For more information about how to retrieve document number from Microsoft Dynamics GP, see Retrieving a document number.
The following Visual Basic example uses the GetNextDocNumbers class to retrieve several types of Microsoft Dynamics GP document numbers.
'Instantiate a GetNextDocNumbers object Dim getDocNumbers As New GetNextDocNumbers() 'Use the GetNextDocNumbers object to retrieve a series of ' Microsoft Dynamics GP document numbers Dim poNumber = getDocNumbers.GetNextPONumber( _ GetNextDocNumbers.IncrementDecrement.Increment, connectionString) Dim invNumber = getDocNumbers.GetNextIVNumber( _ GetNextDocNumbers.IncrementDecrement.Increment, _ GetNextDocNumbers.IVDocType.IVAdjustment, connectionString) Dim rmNumber = getDocNumbers.GetNextRMNumber( _ GetNextDocNumbers.IncrementDecrement.Increment, _ GetNextDocNumbers.RMPaymentType.RMReturn, connectionString) Dim pmNumber = getDocNumbers.GetPMNextVoucherNumber( _ GetNextDocNumbers.IncrementDecrement.Increment, connectionString) Dim sopNumber = getDocNumbers.GetNextSOPNumber( _ GetNextDocNumbers.IncrementDecrement.Increment, "STDINV", _ GetNextDocNumbers.SopType.SOPInvoice, connectionString)
Specify the document number to return
To specify the document numbers to return, create a DocumentRollback object. Use the Add method of the DocumentRollback class to build a list of unused document numbers. To use the Add method, you must specify the document type and the document number. The Add method creates a RollBackDocument object and adds that object to an internal arraylist.
The following Visual Basic example shows how to use the Add method of the DocumentRollback class. Notice how the TransactionType enumeration specifies the type of each document.
'Instantiate a DcoumentRollback object Dim docRollBack As New DocumentRollback() 'Add the document numbers to the DocumentRollback object docRollBack.Add(TransactionType.POP, poNumber) docRollBack.Add(TransactionType.IVTrans, invNumber) docRollBack.Add(TransactionType.RM, rmNumber) docRollBack.Add(TransactionType.PM, pmNumber) docRollBack.Add(TransactionType.SOP, sopNumber)
Search the document number arraylist (optional)
To find information about each document number in a DocumentRollback object, search the arraylist of that object. Since each member of the arraylist is a RollBackDocument object, you can use the document number, document type, and other properties to find important information about each document number in the collection.
The following Visual Basic examples shows how to search for document numbers in a DocumentRollback arraylist. Notice how the ArrayList, the ForEach loop, and the RollBackDocument type are used to create a list of document numbers.
'**Iterate through the document numbers to return** 'Determine whether the document rollback object contains any document numbers If docRollBack.CollectionContainsDocuments() = True Then 'Instantiate an arraylist Dim aList As New ArrayList() 'Load the arraylist with the information about the document numbers aList = docRollBack.RollBackDocuments() 'Instantiate a list of strings Dim returns As New List(Of String) 'Iterate the array list and inspect the document numbers 'Use the RollBackDocument type to provide access to the DocumentNumber ' property of each object in the arraylist For Each number As RollBackDocument In aList returns.Add(number.DocumentNumber) Next End If
Return the document number to Microsoft Dynamics GP
To return one or more document numbers, use the RollBackDocumentList method of the GetNextDocNumbers class. The RollBackDocumentList method requires you to provide an arraylist that contains one or more Microsoft Dynamics GP document numbers.
To provide the arraylist, use the RollBackDocuments method of your DocumentRollback object. The method returns an arraylist that includes the document numbers you previously added to your DocumentRollback object..
The following Visual Basic example shows how to use the RollBackDocumentList method of the GetNextDocNumbers class. Notice how the RollBackDocuments method of the DocumentRollback object supplies the arraylist parameter for the RollBackDocumentList method.
'Use the RollBackDocumentList method of the GetNextDocNumbers ' object to return the unused document numbers 'Use the RollBackDocuments method of the DocumentRollback object ' to specify the document numbers getDocNumbers.RollBackDocumentList(docRollBack.RollBackDocuments(), _ connectionString)