Create new Batch / Get used Batch number

Hello,


I'm inserting invoices for a client and they have requested that they all go into the same batch. 

I can't figure out how to create a new batch and keep using it. The best I can come up with is creating a new batch for each invoice. 

I pull the invoice number from an earlier event. 

retVal = oSOInvoice.nSetKeyValue("InvoiceNo$", "<xsl:value-of select="$InvoiceNo"/>")

If oSOInvoice.nBatchEnabled = 1 Then
sBatchNo = ""
retVal = oSOInvoice.nSelectBatch(sBatchNo)
End If

retVal = oSOInvoice.nSetKey("<xsl:value-of select="$InvoiceNo"/>")

I just don't know how to select an existing batch for the day. 

  • 0
    I believe the method is retVal = oSOInvoice.nGetNextBatchNo(sBatchNo) (going from memory so I'm not 100% sure). After that, you would use the nSelectBatch(sBatchNo) to continue to add to that batch.
  • 0

    I have done this with AP Invoices in C#.  Here is how I did it...

    1. You will need to create a variable for your batch number and set it to nothing.  Make sure that the batch number is set to nothing outside of your invoice loop.

    2. After you instantiate your AP/AR invoice business object, you need to check to see if your batch number variable is empty.

    a. If empty, use the "nSelecteNewBatch" method to create a new batch.

    b. If not empty, use the "nSelectBatch" method to use the existing batch and pass in the batch number.


    3. Create your invoice.

    4. If your batch number variable is empty, set it using the "sGetKey" method.

    Here are some code snippets:


    Do this right after you instantiate your AP/AR_Invoice_bus object...

    //Check to see if Batches are enabled.  Will return 1 if enabled and 0 if not.
    if (ap_inv_bus.InvokeMethod("nBatchEnabled").ToString() == "1")
    {
        if (string.IsNullOrEmpty(batchNo))
        {
            //nSelectNewBatch - First argument is batch number, second is private (Y/N), third is batch comment.  Leaving batch number blank will get next batch number.
            ap_inv_bus.InvokeMethod("nSelectNewBatch", "", "N", batchComment);
        }
        else
        {
            ap_inv_bus.InvokeMethod("nSelectBatch", batchNo);
        }
    }

    Do this after you have successfully created your invoice....

    if(string.IsNullOrEmpty(batchNo))
    {
        //Set index to include batch number
        batchNo = ap_inv_bus.InvokeMethod("sGetKey", "KBATCH").ToString().Substring(0, 5).TrimEnd();
    }