Are you doing this thru external BOI? Do you know the Batch No ahead of time? Here's an old example snippet of using batches:
'Instantiate a S/O Invoice business object
oSEC = oSS.nSetProgram(oSS.nLookupTask(""SO_Invoice_ui""))
Set o = oScript.NewObject(""SO_Invoice_bus"", oSS)
' Check the BatchEnabled property to determine if batches are enabled
IF o.nBatchEnabled = 1 Then
' Call the SelectBatch method to open an existing batch or create a new
' batch. This method takes the Batch Number as a single argument. If
' Batch Number is null, a new batch will be created and the new batch
' number will be returned in the Batch Number argument.
' Example:
'BatchNo = <<Existing BatchNo>> or BatchNo = """" for new batch
'o.nSelectbatch(BatchNo)
' Call the SelectNewBatch method to create a new batch and set the Private
' Batch flag and Batch Comment. This method takes 3 arguments: Batch
' Number (set to null), Private Batch set to ""Y"" or ""N"", and the Batch
' Comment. The new batch number will be returned in the Batch Number
' argument. Example:
BatchNo = """"
PrivateFlag = ""Y""
CommentText = ""This is a comment""
r = o.nSelectNewBatch(BatchNo, PrivateFlag, CommentText)
End If